[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Improve visibility of "--version" option

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: 2006-06-27 01:43:36 CEST

A few users have commented that they haven't been able to discover the
"--version" option. This patch lists it in the main "help" output, where it
should be.

I added a line under "usage" in each of five "svn*" programs. (The other two
already list all their option switches.) In four cases "--version" outputs a
list of FS or RA modules and I added another line mentioning that.

I considered using the option-description line generated from the option table,
but it doesn't fit well into the style of this help display. I also considered
other changes to the help, such as mentioning "--help" in a similar way to
"--version", but decided to keep to the one purpose.

Any comments on the patch before I commit it?

Basically the change looks something like this:

OLD:
> $ svn help help
> help (?, h): Describe the usage of this program or its subcommands.
> usage: help [SUBCOMMAND...]
>
> Valid options:
> --version : print client version info
> -q [--quiet] : print as little as possible
> --config-dir arg : read user configuration files from directory ARG

NEW:
> $ svn help
> usage: svn <subcommand> [options] [args]
> svn --version [--quiet]
> Subversion command-line client, version 1.5.0-dev.
> Type 'svn help <subcommand>' for help on a specific subcommand.
> Type 'svn --version' to see the program version and RA modules.
>
> Most subcommands take file and/or directory arguments, recursing
[...]

- Julian

Improve visibility of the "--version" option; fix quirks in parsing it.

Describe "--version" in the main help display rather than as an option to
the "help" subcommand, for logical correctness and so users can reasonably
find it. Remove "--version" and "--quiet" options from the "help" command.
Do not allow "--version" to be combined with "help" or any other arguments
or options.

* subversion/svn/help-cmd.c
  (svn_cl__help): Mention "--version" in the main help.

* subversion/svn/main.c
  (svn_cl__cmd_table): Remove "--version" and "--quiet" from "help" command.
  (main): Allow "--version" to take "--quiet" and "--config-dir" options.
    Suppress a misleading error message for "svn --version --OTHER-OPTION".

* subversion/svnadmin/main.c,
* subversion/svndumpfilter/main.c,
* subversion/svnlook/main.c
  (cmd_table): Remove "--version" from "help" command.
  (subcommand_help): Mention "--version" in the main help.
  (main): Suppress a misleading error message for "--version --OTHER-OPTION".

* subversion/svnsync/main.c
  (svnsync_cmd_table): Remove "--version" from "help" command.
  (help_cmd): Mention "--version" in the main help.
  (main): Suppress a misleading error message for "--version --OTHER-OPTION".

Index: subversion/svn/help-cmd.c
===================================================================
--- subversion/svn/help-cmd.c (revision 20223)
+++ subversion/svn/help-cmd.c (working copy)
@@ -43,8 +43,10 @@ svn_cl__help(apr_getopt_t *os,
   /* xgettext: the %s is for SVN_VER_NUMBER. */
   char help_header_template[] =
   N_("usage: svn <subcommand> [options] [args]\n"
+ " svn --version [--quiet]\n"
      "Subversion command-line client, version %s.\n"
      "Type 'svn help <subcommand>' for help on a specific subcommand.\n"
+ "Type 'svn --version' to see the program version and RA modules.\n"
      "\n"
      "Most subcommands take file and/or directory arguments, recursing\n"
      "on the directories. If no arguments are supplied to such a\n"
Index: subversion/svn/main.c
===================================================================
--- subversion/svn/main.c (revision 20223)
+++ subversion/svn/main.c (working copy)
@@ -346,11 +346,8 @@ const svn_opt_subcommand_desc2_t svn_cl_
   { "help", svn_cl__help, {"?", "h"}, N_
     ("Describe the usage of this program or its subcommands.\n"
      "usage: help [SUBCOMMAND...]\n"),
- {svn_cl__version_opt, 'q', svn_cl__config_dir_opt} },
- /* We need to support "--help", "-?", and all that good stuff, of
- course. But those options, since unknown, will result in the
- help message being printed out anyway, so there's no need to
- support them explicitly. */
+ {svn_cl__config_dir_opt} },
+ /* This command is also invoked if we see option "--help", "-h" or "-?". */
 
   { "import", svn_cl__import, {0}, N_
     ("Commit an unversioned file or tree into the repository.\n"
@@ -1048,7 +1045,6 @@ main(int argc, const char *argv[])
         break;
       case svn_cl__version_opt:
         opt_state.version = TRUE;
- opt_state.help = TRUE;
         break;
       case svn_cl__auth_username_opt:
         err = svn_utf_cstring_to_utf8(&opt_state.auth_username,
@@ -1207,12 +1203,27 @@ main(int argc, const char *argv[])
     {
       if (os->ind >= os->argc)
         {
- svn_error_clear
- (svn_cmdline_fprintf(stderr, pool,
- _("Subcommand argument required\n")));
- svn_cl__help(NULL, NULL, pool);
- svn_pool_destroy(pool);
- return EXIT_FAILURE;
+ if (opt_state.version)
+ {
+ /* Use the "help" subcommand to handle the "--version" option. */
+ static const svn_opt_subcommand_desc2_t pseudo_cmd =
+ { "--version", svn_cl__help, {0}, "",
+ {svn_cl__version_opt, /* must accept its own option */
+ 'q', /* brief output */
+ svn_cl__config_dir_opt /* all commands accept this */
+ } };
+
+ subcommand = &pseudo_cmd;
+ }
+ else
+ {
+ svn_error_clear
+ (svn_cmdline_fprintf(stderr, pool,
+ _("Subcommand argument required\n")));
+ svn_cl__help(NULL, NULL, pool);
+ svn_pool_destroy(pool);
+ return EXIT_FAILURE;
+ }
         }
       else
         {
@@ -1259,11 +1270,14 @@ main(int argc, const char *argv[])
               || (err = svn_utf_cstring_to_utf8(&cmdname_utf8,
                                                 subcommand->name, pool)))
             return svn_cmdline_handle_exit_error(err, pool, "svn: ");
- svn_error_clear
- (svn_cmdline_fprintf
- (stderr, pool, _("Subcommand '%s' doesn't accept option '%s'\n"
- "Type 'svn help %s' for usage.\n"),
- cmdname_utf8, optstr_utf8, cmdname_utf8));
+ if (subcommand->name[0] == '-')
+ svn_cl__help(NULL, NULL, pool);
+ else
+ svn_error_clear
+ (svn_cmdline_fprintf
+ (stderr, pool, _("Subcommand '%s' doesn't accept option '%s'\n"
+ "Type 'svn help %s' for usage.\n"),
+ cmdname_utf8, optstr_utf8, cmdname_utf8));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }
Index: subversion/svnadmin/main.c
===================================================================
--- subversion/svnadmin/main.c (revision 20223)
+++ subversion/svnadmin/main.c (working copy)
@@ -329,7 +329,7 @@ static const svn_opt_subcommand_desc_t c
   {"help", subcommand_help, {"?", "h"}, N_
    ("usage: svnadmin help [SUBCOMMAND...]\n\n"
     "Describe the usage of this program or its subcommands.\n"),
- {svnadmin__version} },
+ {0} },
 
   {"hotcopy", subcommand_hotcopy, {0}, N_
    ("usage: svnadmin hotcopy REPOS_PATH NEW_REPOS_PATH\n\n"
@@ -652,7 +652,9 @@ subcommand_help(apr_getopt_t *os, void *
   struct svnadmin_opt_state *opt_state = baton;
   const char *header =
     _("general usage: svnadmin SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]\n"
+ " svnadmin --version\n"
       "Type 'svnadmin help <subcommand>' for help on a specific subcommand.\n"
+ "Type 'svnadmin --version' to see the program version and FS modules.\n"
       "\n"
       "Available subcommands:\n");
 
@@ -1255,7 +1257,6 @@ main(int argc, const char *argv[])
         break;
       case svnadmin__version:
         opt_state.version = TRUE;
- opt_state.help = TRUE;
         break;
       case svnadmin__incremental:
         opt_state.incremental = TRUE;
@@ -1332,12 +1333,25 @@ main(int argc, const char *argv[])
     {
       if (os->ind >= os->argc)
         {
- svn_error_clear
- (svn_cmdline_fprintf(stderr, pool,
- _("subcommand argument required\n")));
- subcommand_help(NULL, NULL, pool);
- svn_pool_destroy(pool);
- return EXIT_FAILURE;
+ if (opt_state.version)
+ {
+ /* Use the "help" subcommand to handle the "--version" option. */
+ static const svn_opt_subcommand_desc_t pseudo_cmd =
+ { "--version", subcommand_help, {0}, "",
+ {svnadmin__version, /* must accept its own option */
+ } };
+
+ subcommand = &pseudo_cmd;
+ }
+ else
+ {
+ svn_error_clear
+ (svn_cmdline_fprintf(stderr, pool,
+ _("subcommand argument required\n")));
+ subcommand_help(NULL, NULL, pool);
+ svn_pool_destroy(pool);
+ return EXIT_FAILURE;
+ }
         }
       else
         {
@@ -1413,11 +1427,14 @@ main(int argc, const char *argv[])
           const apr_getopt_option_t *badopt =
             svn_opt_get_option_from_code(opt_id, options_table);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
- svn_error_clear
- (svn_cmdline_fprintf
- (stderr, pool, _("subcommand '%s' doesn't accept option '%s'\n"
- "Type 'svnadmin help %s' for usage.\n"),
- subcommand->name, optstr, subcommand->name));
+ if (subcommand->name[0] == '-')
+ subcommand_help(NULL, NULL, pool);
+ else
+ svn_error_clear
+ (svn_cmdline_fprintf
+ (stderr, pool, _("subcommand '%s' doesn't accept option '%s'\n"
+ "Type 'svnadmin help %s' for usage.\n"),
+ subcommand->name, optstr, subcommand->name));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }
Index: subversion/svndumpfilter/main.c
===================================================================
--- subversion/svndumpfilter/main.c (revision 20223)
+++ subversion/svndumpfilter/main.c (working copy)
@@ -816,7 +816,7 @@ static const svn_opt_subcommand_desc_t c
     {"help", subcommand_help, {"?", "h"},
      N_("Describe the usage of this program or its subcommands.\n"
         "usage: svndumpfilter help [SUBCOMMAND...]\n"),
- {svndumpfilter__version} },
+ {0} },
 
     { NULL, NULL, {0}, NULL, {0} }
   };
@@ -886,6 +886,7 @@ subcommand_help(apr_getopt_t *os, void *
   struct svndumpfilter_opt_state *opt_state = baton;
   const char *header =
     _("general usage: svndumpfilter SUBCOMMAND [ARGS & OPTIONS ...]\n"
+ " svndumpfilter --version\n"
       "Type 'svndumpfilter help <subcommand>' for help on a "
       "specific subcommand.\n"
       "\n"
@@ -1155,7 +1156,6 @@ main(int argc, const char *argv[])
           break;
         case svndumpfilter__version:
           opt_state.version = TRUE;
- opt_state.help = TRUE;
         case svndumpfilter__quiet:
           opt_state.quiet = TRUE;
           break;
@@ -1190,11 +1190,25 @@ main(int argc, const char *argv[])
     {
       if (os->ind >= os->argc)
         {
- svn_error_clear(svn_cmdline_fprintf
- (stderr, pool, _("Subcommand argument required\n")));
- subcommand_help(NULL, NULL, pool);
- svn_pool_destroy(pool);
- return EXIT_FAILURE;
+ if (opt_state.version)
+ {
+ /* Use the "help" subcommand to handle the "--version" option. */
+ static const svn_opt_subcommand_desc_t pseudo_cmd =
+ { "--version", subcommand_help, {0}, "",
+ {svndumpfilter__version, /* must accept its own option */
+ } };
+
+ subcommand = &pseudo_cmd;
+ }
+ else
+ {
+ svn_error_clear(svn_cmdline_fprintf
+ (stderr, pool,
+ _("Subcommand argument required\n")));
+ subcommand_help(NULL, NULL, pool);
+ svn_pool_destroy(pool);
+ return EXIT_FAILURE;
+ }
         }
       else
         {
@@ -1267,11 +1281,14 @@ main(int argc, const char *argv[])
           const apr_getopt_option_t *badopt =
             svn_opt_get_option_from_code(opt_id, options_table);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
- svn_error_clear(svn_cmdline_fprintf
- (stderr, pool,
- _("Subcommand '%s' doesn't accept option '%s'\n"
- "Type 'svndumpfilter help %s' for usage.\n"),
- subcommand->name, optstr, subcommand->name));
+ if (subcommand->name[0] == '-')
+ subcommand_help(NULL, NULL, pool);
+ else
+ svn_error_clear(svn_cmdline_fprintf
+ (stderr, pool,
+ _("Subcommand '%s' doesn't accept option '%s'\n"
+ "Type 'svndumpfilter help %s' for usage.\n"),
+ subcommand->name, optstr, subcommand->name));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }
Index: subversion/svnlook/main.c
===================================================================
--- subversion/svnlook/main.c (revision 20223)
+++ subversion/svnlook/main.c (working copy)
@@ -169,7 +169,7 @@ static const svn_opt_subcommand_desc_t c
   {"help", subcommand_help, {"?", "h"},
    N_("usage: svnlook help [SUBCOMMAND...]\n\n"
       "Describe the usage of this program or its subcommands.\n"),
- {svnlook__version} },
+ {0} },
 
   {"history", subcommand_history, {0},
    N_("usage: svnlook history REPOS_PATH [PATH_IN_REPOS]\n\n"
@@ -1651,10 +1651,12 @@ subcommand_help(apr_getopt_t *os, void *
   struct svnlook_opt_state *opt_state = baton;
   const char *header =
     _("general usage: svnlook SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]\n"
+ " svnlook --version\n"
       "Note: any subcommand which takes the '--revision' and '--transaction'\n"
       " options will, if invoked without one of those options, act on\n"
       " the repository's youngest revision.\n"
       "Type 'svnlook help <subcommand>' for help on a specific subcommand.\n"
+ "Type 'svnlook --version' to see the program version and FS modules.\n"
       "\n"
       "Available subcommands:\n");
 
@@ -1965,7 +1967,6 @@ main(int argc, const char *argv[])
 
         case svnlook__version:
           opt_state.version = TRUE;
- opt_state.help = TRUE;
           break;
 
         case svnlook__show_ids:
@@ -2020,12 +2021,25 @@ main(int argc, const char *argv[])
     {
       if (os->ind >= os->argc)
         {
- svn_error_clear
- (svn_cmdline_fprintf(stderr, pool,
- _("Subcommand argument required\n")));
- subcommand_help(NULL, NULL, pool);
- svn_pool_destroy(pool);
- return EXIT_FAILURE;
+ if (opt_state.version)
+ {
+ /* Use the "help" subcommand to handle the "--version" option. */
+ static const svn_opt_subcommand_desc_t pseudo_cmd =
+ { "--version", subcommand_help, {0}, "",
+ {svnlook__version, /* must accept its own option */
+ } };
+
+ subcommand = &pseudo_cmd;
+ }
+ else
+ {
+ svn_error_clear
+ (svn_cmdline_fprintf(stderr, pool,
+ _("Subcommand argument required\n")));
+ subcommand_help(NULL, NULL, pool);
+ svn_pool_destroy(pool);
+ return EXIT_FAILURE;
+ }
         }
       else
         {
@@ -2127,12 +2141,15 @@ main(int argc, const char *argv[])
           const apr_getopt_option_t *badopt =
             svn_opt_get_option_from_code(opt_id, options_table);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
- svn_error_clear
- (svn_cmdline_fprintf
- (stderr, pool,
- _("Subcommand '%s' doesn't accept option '%s'\n"
- "Type 'svnlook help %s' for usage.\n"),
- subcommand->name, optstr, subcommand->name));
+ if (subcommand->name[0] == '-')
+ subcommand_help(NULL, NULL, pool);
+ else
+ svn_error_clear
+ (svn_cmdline_fprintf
+ (stderr, pool,
+ _("Subcommand '%s' doesn't accept option '%s'\n"
+ "Type 'svnlook help %s' for usage.\n"),
+ subcommand->name, optstr, subcommand->name));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }
Index: subversion/svnsync/main.c
===================================================================
--- subversion/svnsync/main.c (revision 20223)
+++ subversion/svnsync/main.c (working copy)
@@ -77,7 +77,7 @@ static const svn_opt_subcommand_desc_t s
     { "help", help_cmd, { "?", "h" },
       N_("usage: svnsync help [SUBCOMMAND...]\n"
          "Describe the usage of this program or its subcommands.\n"),
- { svnsync_opt_version } },
+ { 0 } },
     { NULL, NULL, { 0 }, NULL, { 0 } }
   };
 
@@ -1132,7 +1132,9 @@ help_cmd(apr_getopt_t *os, void *baton,
 
   const char *header =
     _("general usage: svnsync SUBCOMMAND DEST_URL [ARGS & OPTIONS ...]\n"
+ " svnsync --version\n"
       "Type 'svnsync help <subcommand>' for help on a specific subcommand.\n"
+ "Type 'svnsync --version' to see the program version and RA modules.\n"
       "\n"
       "Available subcommands:\n");
 
@@ -1250,7 +1252,6 @@ main(int argc, const char *argv[])
 
           case svnsync_opt_version:
             opt_baton.version = TRUE;
- opt_baton.help = TRUE;
             break;
 
           case 'r':
@@ -1287,9 +1288,22 @@ main(int argc, const char *argv[])
     {
       if (os->ind >= os->argc)
         {
- help_cmd(NULL, NULL, pool);
- svn_pool_destroy(pool);
- return EXIT_FAILURE;
+ if (opt_baton.version)
+ {
+ /* Use the "help" subcommand to handle the "--version" option. */
+ static const svn_opt_subcommand_desc_t pseudo_cmd =
+ { "--version", help_cmd, {0}, "",
+ {svnsync_opt_version, /* must accept its own option */
+ } };
+
+ subcommand = &pseudo_cmd;
+ }
+ else
+ {
+ help_cmd(NULL, NULL, pool);
+ svn_pool_destroy(pool);
+ return EXIT_FAILURE;
+ }
         }
       else
         {
@@ -1318,11 +1332,14 @@ main(int argc, const char *argv[])
           const apr_getopt_option_t *badopt =
             svn_opt_get_option_from_code(opt_id, svnsync_options);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
- svn_error_clear
- (svn_cmdline_fprintf
- (stderr, pool, _("subcommand '%s' doesn't accept option '%s'\n"
- "Type 'svnsync help %s' for usage.\n"),
- subcommand->name, optstr, subcommand->name));
+ if (subcommand->name[0] == '-')
+ help_cmd(NULL, NULL, pool);
+ else
+ svn_error_clear
+ (svn_cmdline_fprintf
+ (stderr, pool, _("subcommand '%s' doesn't accept option '%s'\n"
+ "Type 'svnsync help %s' for usage.\n"),
+ subcommand->name, optstr, subcommand->name));
           svn_pool_destroy(pool);
           return EXIT_FAILURE;
         }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jun 27 01:44:00 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.