Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow groups without prefix matches #178

Closed
Leonidas-from-XIV opened this issue Apr 14, 2023 · 3 comments
Closed

Allow groups without prefix matches #178

Leonidas-from-XIV opened this issue Apr 14, 2023 · 3 comments
Labels

Comments

@Leonidas-from-XIV
Copy link

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:

| Group (i, (t, children)) ->
let index = cmd_name_trie children in
match Cmdliner_trie.find index arg with
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
Copy link
Owner

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
Copy link

joprice commented Jul 30, 2023

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
Copy link
Owner

Yes, see the manual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants