Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoking help on a command prints options that don't apply to it #499

Open
andrew-vant opened this issue Jan 18, 2022 · 1 comment
Open

Comments

@andrew-vant
Copy link

andrew-vant commented Jan 18, 2022

Suppose you have a docstring as follows. Its intent is that the -s|--short option applies only to the info command, while the others apply to all commands:

Usage:
    prog --help
    prog info [-s|--short] [options]
    prog do_thing [options]

Commands:
    info       Print information
    do_thing   Do something

Options:

    -s, --short      Shorter output

    -v, --verbose    Verbose output
    -D, --debug      Debug output
    -h, --help       Print help

This does the Right Thing with respect to the options accepted; prog do_thing --short rejects the option and prints usage information. But the output of prog do_thing --help still includes --short. That seems wrong to me; when I do prog subcommand --help, I expect to see only those options that work with subcommand.

Is this a bug, or intended behavior, or is there something I'm missing?

[edit: this is using docopt v0.6.2]

@gsalvatella
Copy link

This is normal, since options can be intermixed with arguments per default unless you pass options_first=True to docopt. Hence doing prog do_thing --help is equivalent to prog --help do_thing. If you want specific help/usage for subcommands, take a look at the git example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants