dbuenzli / cmdliner

Declarative definition of command line interfaces for OCaml
http://erratique.ch/software/cmdliner
ISC License
296 stars 56 forks source link

Allow groups without prefix matches #178

Closed Leonidas-from-XIV closed 1 year ago

Leonidas-from-XIV commented 1 year ago

Hi,

I was surprised to learn that Cmdliner does prefix mapping for names of commands in groups by default. This is pretty cool and can make for convenient CLI usage. But it would also be useful to be able to disable that behavior. Upon taking a look at the code where it is evaluated it seems like it unconditionally constructs a trie and matches the names: https://github.com/dbuenzli/cmdliner/blob/b2f03ea0427feaae59e2a0e02ff020f0d78ccbcf/src/cmdliner_eval.ml#L135-L137 so it doesn't look like that is possible at the moment.

Rationale: When evolving some software commands get added over time, while hopefully old commands keep working. The prefix match can be tricky, because myprog b works if there is only build and exec so people might be inclined to just use that (also in scripts where it is harder to change than in interactive use), but if benchmark is added, suddenly myprog b will fail with an error. Being able to disable the prefix matching can be useful in some cases.

dbuenzli commented 1 year ago

I have said more than once here and there that I regret doing the prefix matching behaviour. On the other hand I also secretly think it's a nice thing to have for interactive users.

In my dreams I believe people are wise enough and do understand that in scripts you should not rely on the prefix behaviour. Of course they are not.

In any case I think it's too late to change these things now and I'm not fond on configurability. More than the wrong choices it took I like the uniform way all cmdliner using programs behave.

joprice commented 1 year ago

Is this meant to apply to args as well? I was surprised to find that with the arg let dry_run = Arg.(value & flag & info [ "d"; "dry-run" ]), I am able to pass every suffix of dry-run, instead of the declared options.

dbuenzli commented 1 year ago

Yes, see the manual.