Skip to content

Support unambiguous abbreviations #732

@adamsmd

Description

@adamsmd

Some programs allow subcommands to be abbreviated with any unambiguous abbreviation of the subcommand name. I would like to request the ability to allow this in picocli.

The key here is that these are not explicitly listed abbreviations, but rather any unambiguous abbreviation of the command name or possibly even its aliases.

For example, in Mercurial, hg showconfig can be run with hg showc, hg show or hg sho. However hg sh and hg s are ambiguous and generate the following errors. (At least they do with the set of Mercurial plugins I have installed. Yours may be different.)

$ hg sh
hg: command 'sh' is ambiguous:
    shelve showconfig
$ hg s
hg: command 's' is ambiguous:
    serve shelve showconfig split squash stabilize status strip summary

Another example is the btrfs filesystem command in which btrfs fi usa / and btrfs f u / are the same as btrfs filesystem usage /.

This concept could also extend to option names. For example Python's argparse, supports this with the allow_abbrev setting.

In the cases I have seen this implemented, "unambiguous abbreviation" really means "unambiguous prefix", but there might be generalizations. (This is not critical to me. It is just a possible point in the design space.) For example, you might allow "foo-bar" to be abbreviated as "f-b" (under the rule that "-" separated words can be abbreviated individually) or "fb" or "fr" (under the rule that abbreviations are subsequences). The latter might be impractical to use (e.g., "fr" becomes ambiguous between "free" and "foo-bar"). I only mention it as it is what is used by Emacs Helm, albeit for interactive input not command lines.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions