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

Include docstring in missing argument error for MultiCommands #133

Closed
cyeb opened this issue Jun 8, 2014 · 12 comments
Closed

Include docstring in missing argument error for MultiCommands #133

cyeb opened this issue Jun 8, 2014 · 12 comments

Comments

@cyeb
Copy link

cyeb commented Jun 8, 2014

Sample code:

import click

@click.group()
def main():
    pass

@main.command()
@click.argument('arg1', nargs=1)
def remove(arg1):
    '''
    Removes arg1.
    '''
    click.echo("Removing %s" % arg1)

if __name__ == '__main__':
    main()

Would like this output:

Usage: asdf.py remove [OPTIONS] ARG1

  Removes arg1.

Options:
  --help  Show this message and exit.

Not this output:

Usage: asdf.py remove [OPTIONS] ARG1

Error: Missing argument "arg1".

---- more verbose description of problem, if needed ----
Doing something like:

python my_code.py remove # missing argument after 'remove'

Prints usage instructions and Error: Missing argument "...", but not the docstring specifying how to use the command 'remove'. To me, it makes more sense for the default behavior to include the docstring specifying how the function should be used for the missing argument error (the text that pops up for "python my_code.py remove --help"). This is the way Git functions.

@mitsuhiko
Copy link
Contributor

Sorry, I do not understand the request. What exactly do you want?

@untitaker
Copy link
Contributor

I think he wants usage errors to show the full help?

@cyeb
Copy link
Author

cyeb commented Jun 9, 2014

Ah, sorry for being unclear -- yes, untitaker puts it in a clearer way. When a subcommand is used wrong, I think it would be more logical to show the full help (as well as have an option for showing which argument is missing).

I mentioned that this is the way Git does it, at least for some of its commands -- typing in the command git mv without any arguments makes it pop up with its full usage instructions:

usage: git mv [options] <source>... <destination>

    -v, --verbose         be verbose
    -n, --dry-run         dry run
    -f, --force           force move/rename even if target exists
    -k                    skip move/rename errors

Which is the behavior I was looking for. If not default behavior, it would be at least logical to have the option without much hassle in configuration.

@mitsuhiko
Copy link
Contributor

I might be okay with having a way to make this optional. I'm not a fan of making this the default as if the help page is too long it's hard to see the error message.

@untitaker
Copy link
Contributor

Maybe just a hint to call --help in the error message?

@aldanor
Copy link

aldanor commented Jul 3, 2014

I'd like to know how to do this as well, can't quite figure it out with the latest Click.

Would be nice to have an option to show help on missing arg; it would also be more consistent with how multi-commands handle this.

@saad-cliqr
Copy link

👍

@izakp
Copy link

izakp commented Apr 6, 2017

This prompt causes some confusion when there are required options for a command. Would like it if the full output of --help could be configured to display, perhaps by a flag to the @command(context_settings={}) dict

@gitlines
Copy link

gitlines commented Jan 5, 2018

I would also love to see not just an error message, but the help page or a reference of how to get to the help page.

If I do not use arguments (e.i. only commands and options) in my click program code and simply type the name of the cli tool I get the help page. However, if an argument is included in my code only the error is shown.

@awfki
Copy link

awfki commented Apr 23, 2018

I'd like this as well. Either show full help on missing argument or at least include something like "Use the --help option for more information.".

Another option would be to allowing adding help to arguments that could provide additional information for the error message.

@untitaker
Copy link
Contributor

untitaker commented Apr 24, 2018 via email

@davidism
Copy link
Member

Decision made to keep current "see --help" message in #502.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants