You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Kobayashi Noritada <no...@dolphin.c.u-tokyo.ac.jp> on 2005/02/23 13:59:56 UTC

[PATCH] svnversion should output its help messages to stdout (Take 2)

Hi,

This is a patch to make the default error message for svnversion shorter
and to add an option '--help', which display the long help message that
is the current default error message.

> If you want to change the behaviour it's probably be better to make
> the error messages shorter, by 1) removing the usage message when
> invalid options are supplied and 2) making a bare 'svnversion' suggest
> adding '--help'.  Then add a --help option that prints the usage to
> stdout.

In this patch I've done as pointed out.

Regards,

-- 
|:  Noritada KOBAYASHI
|:  Dept. of General Systems Studies,
|:  Graduate School of Arts and Sciences, Univ. of Tokyo
|:  E-mail: nori1@dolphin.c.u-tokyo.ac.jp (preferable)
|:          nori@esa.c.u-tokyo.ac.jp


Log:
Make the default error message for svnversion shorter and add an option
'--help', which display the long help message that was the default error
message.

* subversion/svnversion/main.c
(usage): Make the error message shorter, which suggests an option,
  '--help'. Also remove an argument , 'options', which is no longer used
  in the function.
(help): A new function to display the help message, which was the error
  message displayed with 'usage', to stdout.
(main): Add lines for a new option '--help'. Also remove 'options' from
  arguments of 'usage'.


Index: subversion/svnversion/main.c
===================================================================
--- subversion/svnversion/main.c	(revision 13122)
+++ subversion/svnversion/main.c	(working copy)
@@ -117,11 +117,20 @@
 }
 
 static void
-usage(const apr_getopt_option_t *options, apr_pool_t *pool)
+usage(apr_pool_t *pool)
 {
+  svn_error_clear (svn_cmdline_fprintf
+                    (stderr, pool, _("Type 'svnversion --help' for usage.\n")));
+  exit(1);
+}
+
+
+static void
+help(const apr_getopt_option_t *options, apr_pool_t *pool)
+{
   svn_error_clear
     (svn_cmdline_fprintf
-     (stderr, pool,
+     (stdout, pool,
       _("usage: svnversion [OPTIONS] WC_PATH [TRAIL_URL]\n\n"
         "  Produce a compact 'version number' for the working copy path\n"
         "  WC_PATH.  TRAIL_URL is the trailing portion of the URL used to\n"
@@ -150,9 +159,11 @@
     {
       const char *optstr;
       svn_opt_format_option(&optstr, options, TRUE, pool);
-      svn_error_clear (svn_cmdline_fprintf(stderr, pool, "  %s\n", optstr));
+      svn_error_clear (svn_cmdline_fprintf(stdout, pool, "  %s\n", optstr));
       ++options;
     }
+  svn_error_clear (svn_cmdline_fprintf(stdout, pool, "\n"));
+  exit(1);
 }
 
 
@@ -197,6 +208,7 @@
     {
       {"no-newline", 'n', 0, N_("do not output the trailing newline")},
       {"committed",  'c', 0, N_("last changed rather than current revisions")},
+      {"help", 'h', 0, N_("display this help")},
       {"version", SVNVERSION_OPT_VERSION, 0, N_("show version information")},
       {0,             0,  0,  0}
     };
@@ -247,7 +259,7 @@
         break;
       if (status != APR_SUCCESS)
         {
-          usage(options, pool);
+          usage(pool);
           return EXIT_FAILURE;
         }
       switch (opt)
@@ -258,19 +270,22 @@
         case 'c':
           sb.committed = TRUE;
           break;
+	case 'h':
+	  help(options, pool);
+	  break;
         case SVNVERSION_OPT_VERSION:
           SVN_INT_ERR(version(os, pool));
           exit(0);
           break;
         default:
-          usage(options, pool);
+          usage(pool);
           return EXIT_FAILURE;
         }
     }
 
   if (os->ind >= argc || os->ind < argc - 2)
     {
-      usage(options, pool);
+      usage(pool);
       return EXIT_FAILURE;
     }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] svnversion should output its help messages to stdout (Take 2)

Posted by Julian Foad <ju...@btopenworld.com>.
Kobayashi Noritada wrote:
>>exit(0), since displaying the help is now by request and no longer an error.
> 
> BTW 'svnserve -h', which I referred in writing a patch, seems to exit
> with the status code '1' although it outputs the help message as expected:
[...]
> Is this a mistake and shall I fix it?

Yes, that is a mistake.  Please do fix it if you have time.

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] svnversion should output its help messages to stdout (Take 2)

Posted by Kobayashi Noritada <no...@dolphin.c.u-tokyo.ac.jp>.
Hi,

> +1 with that change.

Thanks for your review and approval.
I fixed the exit status and committed it at r13128.

> exit(0), since displaying the help is now by request and no longer an error.

BTW 'svnserve -h', which I referred in writing a patch, seems to exit
with the status code '1' although it outputs the help message as expected:

    svn_error_clear (svn_cmdline_fprintf(stdout, pool, "\n"));
    exit(1);
  }

This bothered me.
Is this a mistake and shall I fix it?
Or is there a reason that should exit at '1'?

Thanks,

-- 
|:  Noritada KOBAYASHI
|:  Dept. of General Systems Studies,
|:  Graduate School of Arts and Sciences, Univ. of Tokyo
|:  E-mail: nori1@dolphin.c.u-tokyo.ac.jp (preferable)
|:          nori@esa.c.u-tokyo.ac.jp

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] svnversion should output its help messages to stdout (Take 2)

Posted by Julian Foad <ju...@btopenworld.com>.
Kobayashi Noritada wrote:
> Hi,
> 
> This is a patch to make the default error message for svnversion shorter
> and to add an option '--help', which display the long help message that
> is the current default error message.

Great.

> Index: subversion/svnversion/main.c
> ===================================================================
> --- subversion/svnversion/main.c	(revision 13122)
> +++ subversion/svnversion/main.c	(working copy)
> @@ -117,11 +117,20 @@
>  }
>  
>  static void
> -usage(const apr_getopt_option_t *options, apr_pool_t *pool)
> +usage(apr_pool_t *pool)
>  {
> +  svn_error_clear (svn_cmdline_fprintf
> +                    (stderr, pool, _("Type 'svnversion --help' for usage.\n")));
> +  exit(1);
> +}
> +
> +
> +static void
> +help(const apr_getopt_option_t *options, apr_pool_t *pool)
> +{
>    svn_error_clear
>      (svn_cmdline_fprintf
> -     (stderr, pool,
> +     (stdout, pool,
>        _("usage: svnversion [OPTIONS] WC_PATH [TRAIL_URL]\n\n"
>          "  Produce a compact 'version number' for the working copy path\n"
>          "  WC_PATH.  TRAIL_URL is the trailing portion of the URL used to\n"
> @@ -150,9 +159,11 @@
>      {
>        const char *optstr;
>        svn_opt_format_option(&optstr, options, TRUE, pool);
> -      svn_error_clear (svn_cmdline_fprintf(stderr, pool, "  %s\n", optstr));
> +      svn_error_clear (svn_cmdline_fprintf(stdout, pool, "  %s\n", optstr));
>        ++options;
>      }
> +  svn_error_clear (svn_cmdline_fprintf(stdout, pool, "\n"));
> +  exit(1);

exit(0), since displaying the help is now by request and no longer an error.

+1 with that change.

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org