This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=934741712f54226c26d909f6210e17164cc8936c

commit 934741712f54226c26d909f6210e17164cc8936c
Author: Guillem Jover <[email protected]>
AuthorDate: Mon May 11 06:14:09 2020 +0200

    dpkg: Add a new --robot option to be used with --version
    
    This option will make --version print its output in a machine parseable
    format.
---
 debian/changelog |  1 +
 man/dpkg.pod     | 12 ++++++++++++
 src/main.c       | 13 ++++++++++---
 src/main.h       |  1 +
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 0c1806144..6446a5935 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -30,6 +30,7 @@ dpkg (1.20.1) UNRELEASED; urgency=medium
     stripping trailing whitespace, and were not prefixing empty lines with
     a ‘.’, like when printing with the field names.
     Reported by Paul Wise <[email protected]>.
+  * dpkg: Add a new --robot option to be used with --version.
   * Portability:
     - libdpkg: When using uselocale(), include <xlocale.h> for locale_t if
       the header is available. Needed on BSDs.
diff --git a/man/dpkg.pod b/man/dpkg.pod
index b42874366..85a9cfe81 100644
--- a/man/dpkg.pod
+++ b/man/dpkg.pod
@@ -512,6 +512,9 @@ Give help about debugging options.
 
 Display B<dpkg> version information.
 
+When used with B<--robot>, the output will be the program version number
+in a dotted numerical format, with no newline.
+
 =item B<dpkg-deb actions>
 
 See B<dpkg-deb>(1) for more information about the following actions,
@@ -1000,6 +1003,15 @@ B<keep>.
 
 =back
 
+=item B<--robot>
+
+Use a machine-readable output format. This provides an interface for programs
+that need to parse the output of some of the commands that do not otherwise
+emit a machine-readable output format. No localization will be used, and the
+output will be modified to make it easier to parse.
+
+The only currently supported command is B<--version>.
+
 =item B<--no-pager>
 
 Disables the use of any pager when showing information (since dpkg 1.19.2).
diff --git a/src/main.c b/src/main.c
index 602d4d5d3..ccf589bfb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -58,11 +58,15 @@
 static void DPKG_ATTR_NORET
 printversion(const struct cmdinfo *ci, const char *value)
 {
-  printf(_("Debian '%s' package management program version %s.\n"),
-         DPKG, PACKAGE_RELEASE);
-  printf(_(
+  if (f_robot) {
+    printf("%s", PACKAGE_RELEASE);
+  } else {
+    printf(_("Debian '%s' package management program version %s.\n"),
+           DPKG, PACKAGE_RELEASE);
+    printf(_(
 "This is free software; see the GNU General Public License version 2 or\n"
 "later for copying conditions. There is NO warranty.\n"));
+  }
 
   m_output(stdout, _("<standard output>"));
 
@@ -163,6 +167,7 @@ usage(const struct cmdinfo *ci, const char *value)
 "  --no-force-...|--refuse-...\n"
 "                             Stop when problems encountered.\n"
 "  --abort-after <n>          Abort after encountering <n> errors.\n"
+"  --robot                    Use machine-readable output on some commands.\n"
 "\n"), ADMINDIR);
 
   printf(_(
@@ -189,6 +194,7 @@ static const char printforhelp[] = N_(
 "\n"
 "Options marked [*] produce a lot of output - pipe it through 'less' or 'more' 
!");
 
+int f_robot = 0;
 int f_pending=0, f_recursive=0, f_alsoselect=1, f_skipsame=0, f_noact=0;
 int f_autodeconf=0, f_nodebsig=0;
 int f_triggers = 0;
@@ -596,6 +602,7 @@ static const struct cmdinfo cmdinfos[]= {
   { "no-also-select",    'N', 0, &f_alsoselect, NULL,      NULL,    0 },
   { "skip-same-version", 'E', 0, &f_skipsame,   NULL,      NULL,    1 },
   { "auto-deconfigure",  'B', 0, &f_autodeconf, NULL,      NULL,    1 },
+  { "robot",             0,   0, &f_robot,      NULL,      NULL,    1 },
   { "root",              0,   1, NULL,          NULL,      set_root,      0 },
   { "abort-after",       0,   1, &errabort,     NULL,      set_integer,   0 },
   { "admindir",          0,   1, NULL,          &admindir, NULL,          0 },
diff --git a/src/main.h b/src/main.h
index 3418c7bcc..5870c560a 100644
--- a/src/main.h
+++ b/src/main.h
@@ -122,6 +122,7 @@ enum action {
 
 extern const char *const statusstrings[];
 
+extern int f_robot;
 extern int f_pending, f_recursive, f_alsoselect, f_skipsame, f_noact;
 extern int f_autodeconf, f_nodebsig;
 extern int f_triggers;

-- 
Dpkg.Org's dpkg

Reply via email to