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.
Sorry, I do not understand the request. What exactly do you want?
I think he wants usage errors to show the full help?
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.
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.
Maybe just a hint to call --help in the error message?
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.
:+1:
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
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.
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.
The latter already happens to my knowledge (hint to use --help), but I might be misremembering
something.
On Mon, Apr 23, 2018 at 09:48:32AM -0700, Dave wrote:
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.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/pallets/click/issues/133#issuecomment-383644304
Decision made to keep current "see --help" message in #502.
Most helpful comment
Maybe just a hint to call
--helpin the error message?