Skip to content

Conversation

@one-d-wide
Copy link
Contributor

Consider the cargo build as an example:

$ cargo build --help
Usage: cargo build [OPTIONS]

Options:
      --future-incompat-report  Outputs a future incompatibility report at the end of the build
      --message-format <FMT>    Error format
  -v, --verbose...              Use verbose output (-vv very verbose/build.rs output)
  -q, --quiet                   Do not print cargo log messages
      --color <WHEN>            Coloring: auto, always, never
      --config <KEY=VALUE>      Override a configuration value
  -Z <FLAG>                     Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
  -h, --help                    Print help
...

Currently with how argh generate usage line this would look like:

Usage: cargo build [--future-incompat-report] [--message-format <fmt>] [-v] [-q] [--color <when>] [--config <key=value>] [-Z <flag>]
...

It's too long, barely readable, and also looks terrible when it gets split in multiple lines by the terminal. And there's no option around it.

We already provide an exhausting information in help. So I suggest adding an option to only outline the most useful parameters in usage, for example the following:

Usage: cargo build [-v] [-q] [--bin <name>] [--release]

This is done by adding usage attribute to fields we want to see in usage, other option are then hidden from the usage line by default.

#[derive(FromArgs)]
struct CliArgs {
...
    #[argh(option)]
    #[argh(usage)] // <--
    release: bool,
...
}

There is also a catch-all option to override the usage line entirely, so it's possible to reproduce what cargo build command has.

#[derive(FromArgs)]
#[argh(usage = "[OPTIONS]")] // <--
struct CliArgs {
...
}

Producing:

Usage: cargo build [OPTIONS]

I also rearranged components in the generated usage line and added a [--] hint. Previously positional arguments went first before options, which is kinda misleading, since positionals may themselves start with -.

So without subcommand it's now [options...] [--] [positional...] and with it [options...] [positional...] [subcommand...].

The fuchsia cli guide doesn't specify on this. And I hasn't found any reason for why it wasn't that way before.

@sadmac7000 sadmac7000 merged commit 087a068 into google:master May 9, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants