Procházet zdrojové kódy

dpkg-parsechangelog: Add new --show-field option to print a field value

One of the most common uses of this program is to retrieve specific
field values from debian/rules file, but currently the output needs
to be filtered, which might introduce subtle bugs. This option will
make life easier for packagers, among others.

Closes: #284664
Guillem Jover před 14 roky
rodič
revize
72c2242d47
3 změnil soubory, kde provedl 16 přidání a 2 odebrání
  1. 2 0
      debian/changelog
  2. 5 1
      man/dpkg-parsechangelog.1
  3. 9 1
      scripts/dpkg-parsechangelog.pl

+ 2 - 0
debian/changelog

@@ -18,6 +18,8 @@ dpkg (1.17.0) UNRELEASED; urgency=low
   * Fix clang warnings due to change of alignment requirements.
   * Change copyright file to point to GPL-2 instead of GPL.
   * Do not pass -e in shell script shebangs, set it in the body.
+  * Add new dpkg-parsechangelog --show-field option to print a field value.
+    Closes: #284664
 
  -- Guillem Jover <guillem@debian.org>  Fri, 03 Aug 2012 13:21:00 +0200
 

+ 5 - 1
man/dpkg-parsechangelog.1

@@ -19,7 +19,7 @@
 .\" You should have received a copy of the GNU General Public License
 .\" along with this program.  If not, see <http://www.gnu.org/licenses/>.
 .
-.TH dpkg\-parsechangelog 1 "2012-05-04" "Debian Project" "dpkg utilities"
+.TH dpkg\-parsechangelog 1 "2012-07-18" "Debian Project" "dpkg utilities"
 .SH NAME
 dpkg\-parsechangelog \- parse Debian changelog files
 .
@@ -53,6 +53,10 @@ which are currently
 .BR /usr/local/lib/dpkg/parsechangelog " and "
 .BR /usr/lib/dpkg/parsechangelog .
 .TP
+.BR \-S ", " \-\-show\-field " \fIfield\fP"
+Specifies the name of the field to show (since dpkg 1.17.0).
+The field name is not printed, only its value.
+.TP
 .BR \-? ", " \-\-help
 Show the usage message and exit.
 .TP

+ 9 - 1
scripts/dpkg-parsechangelog.pl

@@ -30,6 +30,7 @@ use Dpkg::Changelog::Parse;
 textdomain("dpkg-dev");
 
 my %options;
+my $fieldname;
 
 sub version {
     printf _g("Debian %s version %s.\n"), $progname, $version;
@@ -48,6 +49,7 @@ sub usage {
   -l<changelog-file>       get per-version info from this file.
   -F<changelog-format>     force changelog format.
   -L<libdir>               look for changelog parsers in <libdir>.
+  -S, --show-field <field> show the values for <field>.
   -?, --help               show this help message.
       --version            show the version.")
     . "\n\n" . _g(
@@ -81,6 +83,8 @@ while (@ARGV) {
 	$options{"changelogformat"} = $1;
     } elsif (m/^-l(.+)$/) {
 	$options{"file"} = $1;
+    } elsif (m/^-(?:S|-show-field)(?:=(.+))?$/) {
+	$fieldname = $1 // shift(@ARGV);
     } elsif (m/^--$/) {
 	last;
     } elsif (m/^-([cfnostuv])(.*)$/) {
@@ -120,5 +124,9 @@ my $count = 0;
 my @fields = changelog_parse(%options);
 foreach my $f (@fields) {
     print "\n" if $count++;
-    print $f->output();
+    if ($fieldname) {
+        print $f->{$fieldname} . "\n";
+    } else {
+        print $f->output();
+    }
 }