]> git.ipfire.org Git - thirdparty/git.git/commit
maintenance: add parse-options boilerplate for subcommands
authorJeff King <peff@peff.net>
Thu, 25 Aug 2022 10:51:06 +0000 (06:51 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Aug 2022 16:43:30 +0000 (09:43 -0700)
commit0d330a53f31a0885954ac48c5e6d24efd3969039
treec4b0b43056ae8a8f9bbb6a094d4343fccf134bab
parentecd2d3efe04c982eb9b95a2997841634f6a54e45
maintenance: add parse-options boilerplate for subcommands

Several of the git-maintenance subcommands don't take any options, so
they don't bother looking at argv at all. This means they'll silently
accept garbage, like:

  $ git maintenance register --foo
  [no output]

  $ git maintenance stop bar
  [no output]

Let's give them the basic boilerplate to detect and handle these cases:

  $ git maintenance register --foo
  error: unknown option `foo'
  usage: git maintenance register

  $ git maintenance stop bar
  usage: git maintenance stop

We could reduce the number of lines of code here a bit with a shared
helper function. But it's worth building out the boilerplate, as it may
serve as the base for adding options later.

Note one complication: maintenance_start() calls directly into
maintenance_register(), so it now needs to pass a plausible argv (we
don't care, but parse_options() is expecting there to at least be an
argv[0] program name). This is an extra line of code, but it eliminates
the need for an explanatory comment.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c