Re: [PATCH] usage_with_options: omit double new line on empty option list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stefan Beller <sbeller@xxxxxxxxxx> writes:

> Currently the worktree command gives its usage, when no subcommand is
> given. However there are no general options, all options are related to
> the subcommands itself, such that:
>
>     $ git worktree
>     usage: git worktree add [<options>] <path> [<branch>]
>        or: git worktree list [<options>]
>        or: git worktree lock [<options>] <path>
>        or: git worktree prune [<options>]
>        or: git worktree unlock <path>
>
>
>     $
>
> Note the two empty lines at the end of the usage string. This is because
> the toplevel usage is printed with an empty options list.

I have this feeling that this patch may not be sufficient.  

The reason for the first blank line is because we unconditionally
emit one, expecting that we would have a list of options to show and
want to separate the usage from that list, and the fix in this patch
is correct---it is the right way to suppress it.

But why do we need the second blank line in this case?  There is a
similar unconditional LF near the end of this function.  Is somebody
else (other than usage_with_options() which will exit immeidately)
calls this function and expects to say something more after what
this function said, and is this extra blank line at the end is to
prepare for that caller?

> Only print one new line after the usage string if the option list is empty.
>
> Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
> ---
>  parse-options.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/parse-options.c b/parse-options.c
> index 0dd9fc6a0d..1307c82861 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -603,7 +603,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
>  		usagestr++;
>  	}
>  
> -	if (opts->type != OPTION_GROUP)
> +	if (opts->type != OPTION_GROUP && opts->type != OPTION_END)
>  		fputc('\n', outfile);
>  
>  	for (; opts->type != OPTION_END; opts++) {



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux