Explorar el Código

dpkg-parsechangelog: Normalize command-line parsing

This allows them to accept «-ovalue», «-o value», «--option=value» and
«--option value», which are the common option formats people expect.

Closes: #693951
Guillem Jover hace 11 años
padre
commit
148c86fcdf
Se han modificado 4 ficheros con 94 adiciones y 85 borrados
  1. 3 0
      debian/changelog
  2. 15 9
      man/dpkg-parsechangelog.1
  3. 17 21
      scripts/changelog/debian.pl
  4. 59 55
      scripts/dpkg-parsechangelog.pl

+ 3 - 0
debian/changelog

@@ -106,6 +106,9 @@ dpkg (1.18.0) UNRELEASED; urgency=low
   * Check that HAVE_DECL_SYS_SIGLIST is 0 instead of undefined, to fix a
   * Check that HAVE_DECL_SYS_SIGLIST is 0 instead of undefined, to fix a
     build failure on uclibc based systems. Closes: #777044
     build failure on uclibc based systems. Closes: #777044
     Based on a patch by Alex Potapenko <opotapenko@gmail.com>.
     Based on a patch by Alex Potapenko <opotapenko@gmail.com>.
+  * Normalize dpkg-parsechangelog command-line parsing, so that «-ovalue»,
+    «-o value», «--option=value» and «--option value» will all be accepted.
+    Closes: #693951
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]
   * Drop myself from Uploaders.
   * Drop myself from Uploaders.

+ 15 - 9
man/dpkg-parsechangelog.1

@@ -35,19 +35,19 @@ form.
 .
 .
 .SH OPTIONS
 .SH OPTIONS
 .TP
 .TP
-.BI \-l changelog-file
+.BR \-l " \fIchangelog-file\fP"
 Specifies the changelog file to read information from. A '\-' can be
 Specifies the changelog file to read information from. A '\-' can be
 used to specify reading from standard input. The
 used to specify reading from standard input. The
 default is
 default is
 .BR debian/changelog .
 .BR debian/changelog .
 .TP
 .TP
-.BI \-F changelog-format
+.BR \-F " \fIchangelog-format\fP"
 Specifies the format of the changelog. By default the format is read
 Specifies the format of the changelog. By default the format is read
 from a special line near the bottom of the changelog or failing that
 from a special line near the bottom of the changelog or failing that
 defaults to the \fIdebian\fP standard format. See also
 defaults to the \fIdebian\fP standard format. See also
 \fBCHANGELOG FORMATS\fP.
 \fBCHANGELOG FORMATS\fP.
 .TP
 .TP
-.BI \-L libdir
+.BR \-L " \fIlibdir\fP"
 Specify an additional directory to search for parser scripts.
 Specify an additional directory to search for parser scripts.
 This directory is searched before the default directories
 This directory is searched before the default directories
 which are currently
 which are currently
@@ -120,23 +120,27 @@ The \fBrfc822\fP format uses the same fields but outputs
 a separate paragraph for each changelog entry so that all
 a separate paragraph for each changelog entry so that all
 metadata for each entry is preserved.
 metadata for each entry is preserved.
 .TP
 .TP
-.BR \-\-since " \fIversion\fP, " \-s \fIversion\fP, " \-v" \fIversion\fP
+.BR \-s ", " \-\-since " \fIversion\fP"
+.TQ
+.BR \-v " \fIversion\fP"
 include all changes later than \fIversion\fP.
 include all changes later than \fIversion\fP.
 .TP
 .TP
-.BR \-\-until " \fIversion\fP, " \-u \fIversion\fP
+.BR \-u ", " \-\-until " \fIversion\fP"
 include all changes earlier than \fIversion\fP.
 include all changes earlier than \fIversion\fP.
 .TP
 .TP
-.BR \-\-from " \fIversion\fP, " \-f \fIversion\fP
+.BR \-f ", " \-\-from " \fIversion\fP"
 include all changes equal or later than \fIversion\fP.
 include all changes equal or later than \fIversion\fP.
 .TP
 .TP
-.BR \-\-to " \fIversion\fP, " \-t \fIversion\fP
+.BR \-t ", " \-\-to " \fIversion\fP"
 include all changes up to or equal than \fIversion\fP.
 include all changes up to or equal than \fIversion\fP.
 .TP
 .TP
-.BR \-\-count " \fInumber\fP, " \-c "\fInumber\fP, " \-n \fInumber\fP
+.BR \-c ", " \-\-count " \fInumber\fP"
+.TQ
+.BR \-n " \fInumber\fP"
 include \fInumber\fP entries from the top (or the tail
 include \fInumber\fP entries from the top (or the tail
 if \fInumber\fP is lower than 0).
 if \fInumber\fP is lower than 0).
 .TP
 .TP
-.BR \-\-offset " \fInumber\fP, " \-o \fInumber\fP
+.BR \-o ", " \-\-offset " \fInumber\fP"
 change the starting point for \fB\-\-count\fP, counted from the top
 change the starting point for \fB\-\-count\fP, counted from the top
 (or the tail if \fInumber\fP is lower than 0).
 (or the tail if \fInumber\fP is lower than 0).
 .TP
 .TP
@@ -189,6 +193,8 @@ All \fBParser Options\fP except for \fB\-v\fP are only supported
 since dpkg 1.14.16. Third party parsers for
 since dpkg 1.14.16. Third party parsers for
 changelog formats other than \fIdebian\fP might not support
 changelog formats other than \fIdebian\fP might not support
 all options.
 all options.
+.PP
+Short option parsing with non-bundled values available only since dpkg 1.18.0.
 .
 .
 .SH FILES
 .SH FILES
 .TP
 .TP

+ 17 - 21
scripts/changelog/debian.pl

@@ -47,27 +47,23 @@ sub usage {
 "Usage: %s [<option>...] [<changelogfile>]
 "Usage: %s [<option>...] [<changelogfile>]
 
 
 Options:
 Options:
-    -?, --help                  print usage information
-    --version, -V               print version information
-    --label, -l <file>          name of the changelog file to
-                                use in error messages
-    --file <file>               changelog file to parse, defaults
-                                to '-' (standard input)
-    --format <outputformat>     see man page for list of available
-                                output formats, defaults to 'dpkg'
-                                for compatibility with dpkg-dev
-    --since, -s, -v <version>   include all changes later than version
-    --until, -u <version>       include all changes earlier than version
-    --from, -f <version>        include all changes equal or later
-                                than version
-    --to, -t <version>          include all changes up to or equal
-                                than version
-    --count, -c, -n <number>    include <number> entries from the top
-                                (or the tail if <number> is lower than 0)
-    --offset, -o <number>       change the starting point for --count,
-                                counted from the top (or the tail if
-                                <number> is lower than 0)
-    --all                       include all changes
+      --file <file>       changelog <file> to parse (defaults to '-').
+  -l, --label <file>      changelog <file> name to use in error messages.
+      --format <output-format>
+                          set the output format (defaults to 'dpkg').
+      --all               include all changes.
+  -s, --since <version>   include all changes later than <version>.
+  -v <version>            ditto.
+  -u, --until <version>   include all changes earlier than <version>.
+  -f, --from <version>    include all changes equal or later than <version>.
+  -t, --to <version>      include all changes up to or equal than <version>.
+  -c, --count <number>    include <number> entries from the top (or tail if
+                            <number> is lower than 0).
+  -n <number>             ditto.
+  -o, --offset <number>   change starting point for --count, counted from
+                            the top (or tail if <number> is lower than 0).
+  -?, --help              print usage information.
+  -V, --version           print version information.
 "), $Dpkg::PROGNAME;
 "), $Dpkg::PROGNAME;
 }
 }
 
 

+ 59 - 55
scripts/dpkg-parsechangelog.pl

@@ -24,6 +24,7 @@ use warnings;
 
 
 use Dpkg ();
 use Dpkg ();
 use Dpkg::Gettext;
 use Dpkg::Gettext;
+use Dpkg::Getopt;
 use Dpkg::ErrorHandling;
 use Dpkg::ErrorHandling;
 use Dpkg::Changelog::Parse;
 use Dpkg::Changelog::Parse;
 
 
@@ -46,75 +47,78 @@ sub usage {
 'Usage: %s [<option>...]')
 'Usage: %s [<option>...]')
     . "\n\n" . g_(
     . "\n\n" . g_(
 'Options:
 'Options:
-  -l<changelog-file>       get per-version info from this file.
-  -F<changelog-format>     force changelog format.
-  -L<libdir>               look for changelog parsers in <libdir>.
+  -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>.
   -S, --show-field <field> show the values for <field>.
   -?, --help               show this help message.
   -?, --help               show this help message.
       --version            show the version.')
       --version            show the version.')
     . "\n\n" . g_(
     . "\n\n" . g_(
 "Parser options:
 "Parser options:
-    --format <output-format>    see man page for list of available
-                                output formats, defaults to 'dpkg'
-                                for compatibility with dpkg-dev
-    --since <version>,          include all changes later than version
-      -s<version>, -v<version>
-    --until <version>,          include all changes earlier than version
-      -u<version>
-    --from <version>,           include all changes equal or later
-      -f<version>               than version
-    --to <version>, -t<version> include all changes up to or equal
-                                than version
-    --count <number>,           include <number> entries from the top
-      -c<number>, -n<number>    (or the tail if <number> is lower than 0)
-    --offset <number>,          change the starting point for --count,
-      -o<number>                counted from the top (or the tail if
-                                <number> is lower than 0)
-    --all                       include all changes
+      --format <output-format>
+                           set output format (defaults to 'dpkg').
+      --all                include all changes.
+  -s, --since <version>    include all changes later than <version>.
+  -v <version>             ditto.
+  -u, --until <version>    include all changes earlier than <version>.
+  -f, --from <version>     include all changes equal or later than <version>.
+  -t, --to <version>       include all changes up to or equal than <version>.
+  -c, --count <number>     include <number> entries from the top (or tail
+                             if <number> is lower than 0).
+  -n <number>              ditto.
+  -o, --offset <number>    change starting point for --count, counted from
+                             the top (or tail if <number> is lower than 0).
 "), $Dpkg::PROGNAME;
 "), $Dpkg::PROGNAME;
 }
 }
 
 
+@ARGV = normalize_options(@ARGV);
+
 while (@ARGV) {
 while (@ARGV) {
     last unless $ARGV[0] =~ m/^-/;
     last unless $ARGV[0] =~ m/^-/;
-    $_ = shift(@ARGV);
-    if (m/^-L(.+)$/) {
-	$options{libdir} = $1;
-    } elsif (m/^-F([0-9a-z]+)$/) {
-	$options{changelogformat} = $1;
-    } elsif (m/^-l(.+)$/) {
-	$options{file} = $1;
-    } elsif (m/^-S(.+)?$/) {
-	$fieldname = $1 // shift;
-    } elsif (m/^--show-field(?:=(.+))?$/) {
-	$fieldname = $1 // shift(@ARGV);
-    } elsif (m/^--$/) {
-	last;
-    } elsif (m/^-([cfnostuv])(.*)$/) {
-	if (($1 eq 'c') or ($1 eq 'n')) {
-	    $options{count} = $2;
-	} elsif ($1 eq 'f') {
-	    $options{from} = $2;
-	} elsif ($1 eq 'o') {
-	    $options{offset} = $2;
-	} elsif (($1 eq 's') or ($1 eq 'v')) {
-	    $options{since} = $2;
-	} elsif ($1 eq 't') {
-	    $options{to} = $2;
-	} elsif ($1 eq 'u') {
-	    ## no critic (ControlStructures::ProhibitUntilBlocks)
-	    $options{until} = $2;
-	    ## use critic
-	}
-    } elsif (m/^--(count|file|format|from|offset|since|to|until)(?:=(.+))?$/) {
-        $options{$1} = $2 // shift;
-    } elsif (m/^--all$/) {
+
+    my $arg = shift;
+
+    if ($arg eq '--') {
+        last;
+    } elsif ($arg eq '-L') {
+        $options{libdir} = shift;
+        usageerr(g_('missing library directory'))
+            unless length $options{libdir};
+    } elsif ($arg eq '-F') {
+        $options{changelogformat} = shift;
+        usageerr(g_('bad changelog format name'))
+            unless length $options{changelogformat} and
+                          $options{changelogformat} =~ m/^([0-9a-z]+)$/;
+    } elsif ($arg eq '--format') {
+        $options{format} = shift;
+    } elsif ($arg eq '-l' or $arg eq '--file') {
+        $options{file} = shift;
+        usageerr(g_('missing changelog filename'))
+            unless length $options{file};
+    } elsif ($arg eq '-S' or $arg eq '--show-field') {
+        $fieldname = shift;
+    } elsif ($arg eq '-c' or $arg eq '--count' or $arg eq '-n') {
+        $options{count} = shift;
+    } elsif ($arg eq '-f' or $arg eq '--from') {
+        $options{from} = shift;
+    } elsif ($arg eq '-o' or $arg eq '--offset') {
+        $options{offset} = shift;
+    } elsif ($arg eq '-s' or $arg eq '--since' or $arg eq '-v') {
+        $options{since} = shift;
+    } elsif ($arg eq '-t' or $arg eq '--to') {
+        $options{to} = shift;
+    } elsif ($arg eq '-u' or $arg eq '--until') {
+        ## no critic (ControlStructures::ProhibitUntilBlocks)
+        $options{until} = shift;
+        ## use critic
+    } elsif ($arg eq '--all') {
 	$options{all} = undef;
 	$options{all} = undef;
-    } elsif (m/^-(?:\?|-help)$/) {
+    } elsif ($arg eq '-?' or $arg eq '--help') {
 	usage(); exit(0);
 	usage(); exit(0);
-    } elsif (m/^--version$/) {
+    } elsif ($arg eq '--version') {
 	version(); exit(0);
 	version(); exit(0);
     } else {
     } else {
-	usageerr(g_("unknown option \`%s'"), $_);
+	usageerr(g_("unknown option \`%s'"), $arg);
     }
     }
 }
 }
 usageerr(g_('takes no non-option arguments')) if @ARGV;
 usageerr(g_('takes no non-option arguments')) if @ARGV;