Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Access add_subparsers() kwargs #107

Merged
merged 1 commit into from Mar 12, 2016
Merged

Conversation

bsandrow
Copy link
Contributor

Specifically the ability to pass in things like the metavar keyword. It would be nice to just pass metavar='COMMAND' to add_subparsers() rather than getting using a list of all commands as a metavar. This looks really ugly when you have 10+ commands, and it's straining to fit them all into the {,} list.

Specifically the ability to pass in things like the `metavar` keyword. It would be nice to just pass `metavar='COMMAND'` to `add_subparsers()` rather than getting using a list of all commands as a metavar. This looks really ugly when you have 10+ commands, and it's straining to fit them all into the `{,}` list.
@jeffwidman
Copy link
Collaborator

@bsandrow afraid I'm not familiar with the metavar keyword, can you expand on what metavar='COMMAND' means?

I'm open to merging if it's useful functionality, just want to make sure I understand what's actually being added here.

@bsandrow
Copy link
Contributor Author

bsandrow commented Mar 9, 2016

metavar= controls what shows up in the usage string. For example:

parser.add_argument('-f', '--file', metavar='INPUT_FILE')

would show something like:

usage: program [--file INPUT_FILE]

rather than

usage: program [--file FILE]

which would be the default.

When it comes to subparsers, you usually end up with something like this by default:

usage: program {command_1, command_2, command_3}

This gets awkward-looking if you have a lot of commands, but if you pass the metavar= option, you can have something like:

usage: program COMMAND

Note that it's also used in the command list of help as well. metavar is a placeholder that is used anywhere that the help text needs a placeholder to reference where the value would go.

@jeffwidman
Copy link
Collaborator

Thanks, that's a great explanation.

jeffwidman added a commit that referenced this pull request Mar 12, 2016
Access `add_subparsers()` kwargs
@jeffwidman jeffwidman merged commit 0143ed4 into smurfix:master Mar 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants