Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] parse-options: allow grouping subcommands
Date: Fri, 2 Oct 2026 09:19:52 +0200	[thread overview]
Message-ID: <ar9bGF9NqIcol256@pks.im> (raw)
In-Reply-To: <xmqqcxtt5n67.fsf@gitster.g>

On Thu, Oct 01, 2026 at 10:46:24AM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > @@ -1432,35 +1432,39 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
> >  		}
> >  
> >  		pos = usage_indent(outfile);
> > -		if (opts->short_name) {
> > -			if (opts->flags & PARSE_OPT_NODASH)
> > -				pos += fprintf(outfile, "%c", opts->short_name);
> > -			else
> > -				pos += fprintf(outfile, "-%c", opts->short_name);
> > -		}
> > -		if (opts->long_name && opts->short_name)
> > -			pos += fprintf(outfile, ", ");
> > -		if (opts->long_name) {
> > -			const char *long_name = opts->long_name;
> > -			if ((opts->flags & PARSE_OPT_NONEG) ||
> > -			    skip_prefix(long_name, "no-", &positive_name))
> > -				pos += fprintf(outfile, "--%s", long_name);
> > -			else
> > -				pos += fprintf(outfile, "--[no-]%s", long_name);
> > -		}
> 
> It may have made it easier to follow if a preliminary step pushed
> the above to a helper function.  It would have also prevented the
> nesting becoming too deep as we see below.

Will do.

> > diff --git a/parse-options.h b/parse-options.h
> > index d7f896a933..5249404b46 100644
> > --- a/parse-options.h
> > +++ b/parse-options.h
> > @@ -401,6 +401,13 @@ static char *parse_options_noop_ignored_value MAYBE_UNUSED;
> >  	.subcommand_fn = (fn), \
> >  }
> >  #define OPT_SUBCOMMAND(l, v, fn)    OPT_SUBCOMMAND_F((l), (v), (fn), 0)
> > +#define OPT_SUBCOMMAND_H(l, v, fn, h) { \
> > +	.type = OPTION_SUBCOMMAND, \
> > +	.long_name = (l), \
> > +	.value = (v), \
> > +	.help = (h), \
> > +	.subcommand_fn = (fn), \
> > +}
> 
> As presented, _F does not allow you to give it a help, and _H does
> not allow you to give it a flag word.  I would have preferred to see
> OPT_SUBCOMMAND_F to be extended to also take the help text, as we
> only have two existing users in *.c code, rather than adding _H
> variant that is incomplete and keeping _F incomplete.

I was a bit torn here because I honestly wasn't quite sure whether the
_F suffix stands for "full" or "flag". But okay, let's not introduce a
new macro then.

Patrick

  reply	other threads:[~2026-10-02  7:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 10:13 [PATCH 0/3] builtin/refs: introduce subcommand groups Patrick Steinhardt
2026-10-01 10:13 ` [PATCH 1/3] parse-options: fix completion format when first option is skipped Patrick Steinhardt
2026-10-01 17:38   ` Junio C Hamano
2026-10-02  7:19     ` Patrick Steinhardt
2026-10-01 10:13 ` [PATCH 2/3] parse-options: allow grouping subcommands Patrick Steinhardt
2026-10-01 17:46   ` Junio C Hamano
2026-10-02  7:19     ` Patrick Steinhardt [this message]
2026-10-01 10:13 ` [PATCH 3/3] builtin/refs: introduce subcommand groups Patrick Steinhardt
2026-10-01 17:46   ` Junio C Hamano
2026-10-02  8:09 ` [PATCH v2 0/4] " Patrick Steinhardt
2026-10-02  8:09   ` [PATCH v2 1/4] parse-options: fix completion format when first option is skipped Patrick Steinhardt
2026-10-02  8:09   ` [PATCH v2 2/4] parse-options: extract functions to print single option Patrick Steinhardt
2026-10-02  8:09   ` [PATCH v2 3/4] parse-options: allow grouping subcommands Patrick Steinhardt
2026-10-02  8:09   ` [PATCH v2 4/4] builtin/refs: introduce subcommand groups Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ar9bGF9NqIcol256@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox