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

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=3878c7d16c3aa1917ef1ebbd7cfc2cf11de12f65

commit 3878c7d16c3aa1917ef1ebbd7cfc2cf11de12f65
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Nov 27 01:03:45 2022 +0100

    src: Handle --help and --version as proper actions
    
    These are documented, and behave as actions. Change the option parsing
    code to treat them as such.
    
    This will make it possible to use them as safe commands to use for
    trivial functional tests and debugging output.
---
 src/common/actions.h    |  3 +++
 src/deb/main.c          | 16 ++++++++--------
 src/divert/main.c       | 16 ++++++++--------
 src/main/main.c         | 16 ++++++++--------
 src/query/main.c        | 16 ++++++++--------
 src/split/main.c        | 16 ++++++++--------
 src/statoverride/main.c | 16 ++++++++--------
 src/trigger/main.c      | 16 ++++++++--------
 8 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/src/common/actions.h b/src/common/actions.h
index 88b6f632d..a78f329df 100644
--- a/src/common/actions.h
+++ b/src/common/actions.h
@@ -70,6 +70,9 @@ enum action {
        act_avreplace,
        act_avmerge,
        act_forgetold,
+
+       act_help,
+       act_version,
 };
 
 #endif /* DPKG_ACTIONS_H */
diff --git a/src/deb/main.c b/src/deb/main.c
index b4347597a..80886f651 100644
--- a/src/deb/main.c
+++ b/src/deb/main.c
@@ -47,8 +47,8 @@
 
 const char *showformat = "${Package}\t${Version}\n";
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *cip, const char *value)
+static int
+printversion(const char *const *argv)
 {
   printf(_("Debian '%s' package archive backend version %s.\n"),
          BACKEND, PACKAGE_RELEASE);
@@ -58,11 +58,11 @@ printversion(const struct cmdinfo *cip, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *cip, const char *value)
+static int
+usage(const char *const *argv)
 {
   printf(_(
 "Usage: %s [<option>...] <command>\n"
@@ -132,7 +132,7 @@ usage(const struct cmdinfo *cip, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
 static const char printforhelp[] =
@@ -258,6 +258,8 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION("ctrl-tarfile",  0,   0, do_ctrltarfile),
   ACTION("fsys-tarfile",  0,   0, do_fsystarfile),
   ACTION("show",          'W', 0, do_showinfo),
+  ACTION("help",          '?', 0, usage),
+  ACTION("version",       0,   0, printversion),
 
   { "deb-format",    0,   1, NULL,           NULL,         set_deb_format   },
   { "debug",         'D', 0, &debugflag,     NULL,         NULL,          1 },
@@ -271,8 +273,6 @@ static const struct cmdinfo cmdinfos[]= {
   { NULL,            'Z', 1, NULL,           NULL,         set_compress_type  
},
   { NULL,            'S', 1, NULL,           NULL,         
set_compress_strategy },
   { "showformat",    0,   1, NULL,           &showformat,  NULL             },
-  { "help",          '?', 0, NULL,           NULL,         usage            },
-  { "version",       0,   0, NULL,           NULL,         printversion     },
   {  NULL,           0,   0, NULL,           NULL,         NULL             }
 };
 
diff --git a/src/divert/main.c b/src/divert/main.c
index 7d739e845..5ebd9a28d 100644
--- a/src/divert/main.c
+++ b/src/divert/main.c
@@ -63,8 +63,8 @@ static int opt_test = 0;
 static int opt_rename = -1;
 
 
-static void
-printversion(const struct cmdinfo *cip, const char *value)
+static int
+printversion(const char *const *argv)
 {
        printf(_("Debian %s version %s.\n"), dpkg_get_progname(),
               PACKAGE_RELEASE);
@@ -75,11 +75,11 @@ printversion(const struct cmdinfo *cip, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
-static void
-usage(const struct cmdinfo *cip, const char *value)
+static int
+usage(const char *const *argv)
 {
        printf(_(
 "Usage: %s [<option>...] <command>\n"
@@ -118,7 +118,7 @@ usage(const struct cmdinfo *cip, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
 static void
@@ -855,6 +855,8 @@ static const struct cmdinfo cmdinfos[] = {
        ACTION("list",        0, 0, diversion_list),
        ACTION("listpackage", 0, 0, diversion_listpackage),
        ACTION("truename",    0, 0, diversion_truename),
+       ACTION("help",        '?', 0, usage),
+       ACTION("version",     0,   0, printversion),
 
        { "admindir",   0,   1,  NULL,         &admindir, NULL          },
        { "instdir",    0,   1,  NULL,         NULL,      set_instdir,  0 },
@@ -866,8 +868,6 @@ static const struct cmdinfo cmdinfos[] = {
        { "rename",     0,   0,  &opt_rename,  NULL,      NULL, 1       },
        { "no-rename",  0,   0,  &opt_rename,  NULL,      NULL, 0       },
        { "test",       0,   0,  &opt_test,    NULL,      NULL, 1       },
-       { "help",      '?',  0,  NULL,         NULL,      usage         },
-       { "version",    0,   0,  NULL,         NULL,      printversion  },
        {  NULL,        0                                               }
 };
 
diff --git a/src/main/main.c b/src/main/main.c
index 6b10773ae..48082efc0 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -55,8 +55,8 @@
 #include "main.h"
 #include "filters.h"
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *ci, const char *value)
+static int
+printversion(const char *const *argv)
 {
   if (f_robot) {
     printf("%s", PACKAGE_VERSION);
@@ -70,7 +70,7 @@ printversion(const struct cmdinfo *ci, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
 /*
@@ -78,8 +78,8 @@ printversion(const struct cmdinfo *ci, const char *value)
  * dpkg --command-fd
  */
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *ci, const char *value)
+static int
+usage(const char *const *argv)
 {
   printf(_(
 "Usage: %s [<option>...] <command>\n"
@@ -181,7 +181,7 @@ usage(const struct cmdinfo *ci, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
 static const char printforhelp[] = N_(
@@ -571,6 +571,8 @@ static const struct cmdinfo cmdinfos[]= {
 /*
   ACTION( "command-fd",                   'c', act_commandfd,   commandfd     
),
 */
+  ACTION( "help",                           '?', act_help,                 
usage),
+  ACTION( "version",                         0,  act_version,              
printversion),
 
   { "pre-invoke",        0,   1, NULL,          NULL,      set_invoke_hook, 0, 
&pre_invoke_hooks },
   { "post-invoke",       0,   1, NULL,          NULL,      set_invoke_hook, 0, 
&post_invoke_hooks },
@@ -606,8 +608,6 @@ static const struct cmdinfo cmdinfos[]= {
   { "refuse",            0,   2, NULL,          NULL,      set_force_option,   
0 },
   { "no-force",          0,   2, NULL,          NULL,      set_force_option,   
0 },
   { "debug",             'D', 1, NULL,          NULL,      set_debug,     0 },
-  { "help",              '?', 0, NULL,          NULL,      usage,         0 },
-  { "version",           0,   0, NULL,          NULL,      printversion,  0 },
   ACTIONBACKEND( "build",              'b', BACKEND),
   ACTIONBACKEND( "contents",           'c', BACKEND),
   ACTIONBACKEND( "control",            'e', BACKEND),
diff --git a/src/query/main.c b/src/query/main.c
index 6e3fe51ef..a531cc17d 100644
--- a/src/query/main.c
+++ b/src/query/main.c
@@ -778,8 +778,8 @@ set_no_pager(const struct cmdinfo *ci, const char *value)
   pager_enable(false);
 }
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *ci, const char *value)
+static int
+printversion(const char *const *argv)
 {
   printf(_("Debian %s package management program query tool version %s.\n"),
          DPKGQUERY, PACKAGE_RELEASE);
@@ -789,11 +789,11 @@ printversion(const struct cmdinfo *ci, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *ci, const char *value)
+static int
+usage(const char *const *argv)
 {
   printf(_(
 "Usage: %s [<option>...] <command>\n"
@@ -839,7 +839,7 @@ usage(const struct cmdinfo *ci, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
 static const char printforhelp[] = N_(
@@ -858,14 +858,14 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "control-path",                   'c', act_controlpath,   
control_path    ),
   ACTION( "control-list",                    0,  act_controllist,   
control_list    ),
   ACTION( "control-show",                    0,  act_controlshow,   
control_show    ),
+  ACTION( "help",                           '?', act_help,          usage      
     ),
+  ACTION( "version",                         0,  act_version,       
printversion    ),
 
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
   { "root",       0,   1, NULL, NULL,        set_root, 0   },
   { "load-avail", 0,   0, &opt_loadavail, NULL, NULL, 1    },
   { "showformat", 'f', 1, NULL, &showformat, NULL          },
   { "no-pager",   0,   0, NULL, NULL,        set_no_pager  },
-  { "help",       '?', 0, NULL, NULL,        usage         },
-  { "version",    0,   0, NULL, NULL,        printversion  },
   {  NULL,        0,   0, NULL, NULL,        NULL          }
 };
 
diff --git a/src/split/main.c b/src/split/main.c
index e807329a3..7b80b60f9 100644
--- a/src/split/main.c
+++ b/src/split/main.c
@@ -41,8 +41,8 @@
 
 #include "dpkg-split.h"
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *cip, const char *value)
+static int
+printversion(const char *const *argv)
 {
   printf(_("Debian '%s' package split/join tool; version %s.\n"),
          SPLITTER, PACKAGE_RELEASE);
@@ -53,11 +53,11 @@ printversion(const struct cmdinfo *cip, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *cip, const char *value)
+static int
+usage(const char *const *argv)
 {
   printf(_(
 "Usage: %s [<option> ...] <command>\n"
@@ -97,7 +97,7 @@ usage(const struct cmdinfo *cip, const char *value)
 
   m_output(stdout, _("<standard output>"));
 
-  exit(0);
+  return 0;
 }
 
 static const char printforhelp[] = N_("Type dpkg-split --help for help.");
@@ -144,9 +144,9 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION("auto",    'a',  0,  do_auto),
   ACTION("listq",   'l',  0,  do_queue),
   ACTION("discard", 'd',  0,  do_discard),
+  ACTION("help",    '?',  0,  usage),
+  ACTION("version",  0,   0,  printversion),
 
-  { "help",         '?',  0,  NULL, NULL,             usage               },
-  { "version",       0,   0,  NULL, NULL,             printversion        },
   { "depotdir",      0,   1,  NULL, &opt_depotdir,    NULL                },
   { "partsize",     'S',  1,  NULL, NULL,             set_part_size       },
   { "output",       'o',  1,  NULL, &opt_outputfile,  NULL                },
diff --git a/src/statoverride/main.c b/src/statoverride/main.c
index 2dda017c7..491fe79e5 100644
--- a/src/statoverride/main.c
+++ b/src/statoverride/main.c
@@ -54,8 +54,8 @@
 static const char printforhelp[] = N_(
 "Use --help for help about overriding file stat information.");
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *cip, const char *value)
+static int
+printversion(const char *const *argv)
 {
        printf(_("Debian %s version %s.\n"), dpkg_get_progname(),
               PACKAGE_RELEASE);
@@ -66,11 +66,11 @@ printversion(const struct cmdinfo *cip, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *cip, const char *value)
+static int
+usage(const char *const *argv)
 {
        printf(_(
 "Usage: %s [<option> ...] <command>\n"
@@ -101,7 +101,7 @@ usage(const struct cmdinfo *cip, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
 #define FORCE_STATCMD_MASK \
@@ -397,6 +397,8 @@ static const struct cmdinfo cmdinfos[] = {
        ACTION("add",    0, act_install,   statoverride_add),
        ACTION("remove", 0, act_remove,    statoverride_remove),
        ACTION("list",   0, act_listfiles, statoverride_list),
+       ACTION("help",   '?', act_help,    usage),
+       ACTION("version", 0,  act_version, printversion),
 
        { "admindir",   0,   1,  NULL,         &admindir, NULL          },
        { "instdir",    0,   1,  NULL,         NULL,      set_instdir,  0 },
@@ -407,8 +409,6 @@ static const struct cmdinfo cmdinfos[] = {
        { "no-force",   0,   2,  NULL,         NULL,      set_force_option, 0 },
        { "refuse",     0,   2,  NULL,         NULL,      set_force_option, 0 },
        { "update",     0,   0,  &opt_update,  NULL,      NULL, 1       },
-       { "help",       '?', 0,  NULL,         NULL,      usage         },
-       { "version",    0,   0,  NULL,         NULL,      printversion  },
        {  NULL,        0                                               }
 };
 
diff --git a/src/trigger/main.c b/src/trigger/main.c
index 5bf0105ad..541c8239c 100644
--- a/src/trigger/main.c
+++ b/src/trigger/main.c
@@ -44,8 +44,8 @@
 static const char printforhelp[] = N_(
 "Type dpkg-trigger --help for help about this utility.");
 
-static void DPKG_ATTR_NORET
-printversion(const struct cmdinfo *ci, const char *value)
+static int
+printversion(const char *const *argv)
 {
        printf(_("Debian %s package trigger utility version %s.\n"),
               dpkg_get_progname(), PACKAGE_RELEASE);
@@ -56,11 +56,11 @@ printversion(const struct cmdinfo *ci, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
-static void DPKG_ATTR_NORET
-usage(const struct cmdinfo *ci, const char *value)
+static int
+usage(const char *const *argv)
 {
        printf(_(
 "Usage: %s [<option>...] <trigger-name>\n"
@@ -90,7 +90,7 @@ usage(const struct cmdinfo *ci, const char *value)
 
        m_output(stdout, _("<standard output>"));
 
-       exit(0);
+       return 0;
 }
 
 static const char *admindir;
@@ -243,6 +243,8 @@ static const struct cmdinfo cmdinfo_trigger =
 
 static const struct cmdinfo cmdinfos[] = {
        ACTION("check-supported",  0,  0, do_check),
+       ACTION("help",            '?', 0, usage),
+       ACTION("version",          0,  0, printversion),
 
        { "admindir",        0,   1, NULL,     &admindir },
        { "root",            0,   1, NULL,     NULL,       set_root, 0 },
@@ -250,8 +252,6 @@ static const struct cmdinfo cmdinfos[] = {
        { "await",           0,   0, &f_await, NULL,       NULL, 1 },
        { "no-await",        0,   0, &f_await, NULL,       NULL, 0 },
        { "no-act",          0,   0, &f_noact, NULL,       NULL, 1 },
-       { "help",            '?', 0, NULL,     NULL,       usage   },
-       { "version",         0,   0, NULL,     NULL,       printversion  },
        {  NULL  }
 };
 

-- 
Dpkg.Org's dpkg

Reply via email to