Print supported values in synopses, when practical#620
Print supported values in synopses, when practical#620numist wants to merge 8 commits intoapple:mainfrom
Conversation
| USAGE: fruit_store [<purchase|sample|return>] <fruit> [--quantity <quantity>] [--ripeness <under|perfect|over>] | ||
|
|
||
| ARGUMENTS: | ||
| <action> The transaction type (values: purchase, sample, | ||
| return; default: purchase) | ||
| <fruit> The fruit to purchase (values: apple, banana, | ||
| coconut, dragon-fruit, elderberry, fig, grape, | ||
| honeydew) |
There was a problem hiding this comment.
It looks like replacing <action> with its values makes it harder to see the correspondence between the usage string and the help descriptions. Are there existing tools that include values in the usage string like this? What would you think of including the argument name – something like:
USAGE: fruit_store [<action: purchase|sample|return>] <fruit> ...
There was a problem hiding this comment.
I'm certain that I've used a cli before that had this feature, but over the past two weeks I could not remember what it was.
It did have the issue you describe though, and I like your solution! Another possibility is that ArgumentParser only expand values when showing a short help (such as gets printed after a ValidationError) and leaving the behaviour as-is when printing the complete --help output.
There was a problem hiding this comment.
Ohh the tool I'm thinking of is something I use frequently at work. Instead of an expanded --help, it explains multiple subcommands at once and then refers to a man page. To paraphrase:
> foo bar --help
Usage:
foo alice --baz <baz_id> [--[no-]qux] [--[no-]thbpt] [--fix]
foo bar --baz <baz_id> [--[no-]qux] [--blarpy <blarpy>] [--minimal | --details] [--[no-]box] [--[no-]link] [--eh|--bee|--see] (--regex|--exact|--contains|--suffix) <search_term>
…
foo sub-commands and options are documented in the manual page (`man foo`).
I was thinking ArgumentParser's top level help for commands with subcommands is a bit spartan, I wonder if this tool is on to something…
| OVERVIEW: A utility for performing maths. | ||
|
|
||
| USAGE: math <subcommand> | ||
| USAGE: math <add|multiply|stats> |
There was a problem hiding this comment.
Likewise, it seems like this loses the context that add/multiply/stats are subcommands.
|
I'm not fully convinced this is a readability improvement over the valid options appearing below. IMO the synopsis should be succinct and the options below should contain the details. |
|
Reasonable! What got me started down this path was the idea that it should be possible to write a correct invocation of a command after the briefest possible glance at its usage, which is necessarily at odds with brevity (and introduces repetition). Another possibility is that ArgumentParser could expand values only when the options are not explained ("short help", in this reply to Nate) |
|
Coming back to this – what would you think about reducing the scope, so that this adds the supported values for options (e.g. |
|
Done! |
This PR adds support for conditionally expanding argument and subcommand synopses to reflect supported values when there are multiple values and their combined length is not overly onerous.
To use an example from
math, this PR changes the current:to
But does not change the output for commands with a single subcommand or commands with very long subcommands.
Checklist