oxidecomputer / oxide.rs

The Oxide Rust SDK and CLI
Mozilla Public License 2.0
37 stars 12 forks source link

Sort subcommands automatically in help output #751

Closed wfchandler closed 1 month ago

wfchandler commented 1 month ago

By default clap will display subcommands in --help in the order they were added to the Command. In our case the order is random due to the split between commands from progenitor and custom commands added manually.

Set display_order(0) on subcommands to allow clap to sort them automatically.

Before:

  Commands:
    experimental
    certificate
    disk
    floating-ip
    group
    image
    instance
    project
    current-user
    ping          Ping API
    policy
    snapshot
    system
    silo
    ip-pool
    user
    utilization   Fetch resource utilization for user's current silo
    vpc
    auth          Login, logout, and get the status of your authentication.
    docs          Generate CLI docs in JSON format
    completion    Generate shell completion scripts for Oxide CLI commands.
    version       Prints version information about the CLI.
    api           Makes an authenticated HTTP request to the Oxide API and prints the response.
    help          Print this message or the help of the given subcommand(s)

After:

  Commands:
    api           Makes an authenticated HTTP request to the Oxide API and prints the response.
    auth          Login, logout, and get the status of your authentication.
    certificate
    completion    Generate shell completion scripts for Oxide CLI commands.
    current-user
    disk
    docs          Generate CLI docs in JSON format
    experimental
    floating-ip
    group
    image
    instance
    ip-pool
    ping          Ping API
    policy
    project
    silo
    snapshot
    system
    user
    utilization   Fetch resource utilization for user's current silo
    version       Prints version information about the CLI.
    vpc
    help          Print this message or the help of the given subcommand(s)
wfchandler commented 1 month ago

do we want to do the same for args?

I don't think it's necessary. Most commands have only a few args, vs the 20+ subcommands we have. Using cargo as a point of reference, it sorts its subcommands, but the args for commands are not sorted.