On Wed, Oct 25, 2023 at 6:53 PM Emily Shaffer <nasamuffin@xxxxxxxxxx> wrote: > On Thu, Oct 26, 2023 at 07:59:16AM +1100, Sheik wrote: > > Running git bugreport with an invalid CLI argument in a valid Git directory > > does not report error. Expected behaviour would be that it reports an error. > > It looks like parse-options.[ch] helps us here for misspelled dashed > options, like `--diaggnose`. But it doesn't complain when there are > unexpected positional arguments. I think we can just notice if there are > any argc left over, complain, and print usage. > > I put together a quick patch; could be that we don't need to leave this > error about "positional arguments" and can leave it as an exercise to > the reader to compare their previous command to the usage text. I guess > we could also unroll remaining argv but it was just a hair more time > than I wanted to spend ;) > > --- 8< --- > Subject: [PATCH] bugreport: reject positional arguments > > git-bugreport already rejected unrecognized flag arguments, like > `--diaggnose`, but this doesn't help if the user's mistake was to forget > the `--` in front of the argument. This can result in a user's intended > argument not being parsed with no indication to the user that something > went wrong. Since git-bugreport presently doesn't take any positionals > at all, let's reject all positionals and give the user a usage hint. > > Signed-off-by: Emily Shaffer <nasamuffin@xxxxxxxxxx> > --- > diff --git a/builtin/bugreport.c b/builtin/bugreport.c > @@ -126,6 +126,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix) > + if (argc) { > + error(_("git bugreport does not take positional arguments")); > + usage(bugreport_usage[0]); > + } This error message may be somewhat difficult to interpret. Providing additional context could help the user understand the actual problem. For instance: % git bugreport diagnose error: unrecognized argument "diagnose"