Download raw body.
Do not treat -h, -V as errors
On Tue, Sep 29, 2020 at 12:15:55AM +0200, Christian Weisgerber wrote:
> do not treat the -h and -V flags as errors
>
> When run with the -h or -V option, output the help or version text
> to stdout and exit with success (0). Only write usage and help
> information to stderr and exit with error (1) if there is a mistake
> in the command syntax.
>
> --------------------
>
> Please check that I got all combinations right.
>
> OK?
One question below:
> diff 9814e6a376df853a88deb889d68f178c803ad8ca /home/naddy/got
> blob - b8f662a112135fe0364e2a25eb0fe2976ba10cf1
> file + got/got.c
> --- got/got.c
> +++ got/got.c
> @@ -83,7 +83,7 @@ struct got_cmd {
> const char *cmd_alias;
> };
>
> -__dead static void usage(int);
> +__dead static void usage(int, int);
> __dead static void usage_init(void);
> __dead static void usage_import(void);
> __dead static void usage_clone(void);
> @@ -171,16 +171,16 @@ static struct got_cmd got_commands[] = {
> };
>
> static void
> -list_commands(void)
> +list_commands(FILE *fp)
> {
> int i;
>
> - fprintf(stderr, "commands:");
> + fprintf(fp, "commands:");
> for (i = 0; i < nitems(got_commands); i++) {
> struct got_cmd *cmd = &got_commands[i];
> - fprintf(stderr, " %s", cmd->cmd_name);
> + fprintf(fp, " %s", cmd->cmd_name);
> }
> - fputc('\n', stderr);
> + fputc('\n', fp);
> }
>
> int
> @@ -206,7 +206,7 @@ main(int argc, char *argv[])
> Vflag = 1;
> break;
> default:
> - usage(hflag);
> + usage(hflag, 1);
> /* NOTREACHED */
> }
> }
> @@ -218,11 +218,11 @@ main(int argc, char *argv[])
>
> if (Vflag) {
> got_version_print_str();
> - return 1;
> + return 0;
> }
>
> if (argc <= 0)
> - usage(hflag);
> + usage(hflag, 0);
This changes the exit status code from 1 to 0 if got is run without
a subcommand. It looks like exit status should depend on hflag here?
Perhaps: usage(hflag, hflag ? 0 : 1);
The rest looks good to me.
Do not treat -h, -V as errors