Skip to content

Displaying command alias in help/usage #2104

@roxspring

Description

@roxspring

We have two steps that users perform which are conceptually very different, but technically identical. We define each step as a separate command, and so we've implemented these technically identical steps as a single step1 command with a step2 alias. Technically this works well, but it's a little confusing to ask for help for step2 and get shown help apparently for step1.

Given a subcommand with an alias, is it possible to have that alias used in the help/usage?

@Command(name = "sub", aliases = "alias", mixinStandardHelpOptions = true) class Sub {}
@Command(name = "app", subcommands = {Sub.class}) class App {}

StringWriter out = new StringWriter();
CommandLine app = new CommandLine(new App(), new InnerClassFactory(this));
app.setOut(new PrintWriter(out));
ParseResult result = app.parseArgs("alias", "--help");
CommandLine.printHelpIfRequested(result);

final String expected = format("" +
        "Usage: app alias [-hV]%n" +
        "  -h, --help      Show this help message and exit.%n" +
        "  -V, --version   Print version information and exit.%n");
assertEquals(expected, out.toString());

If it's already possible, I'd love to understand what I'm missing.

If not, and it's welcome, then I'm happy to take recommendations how to implement it and submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions