click icon indicating copy to clipboard operation
click copied to clipboard

Include docstring in missing argument error for MultiCommands

Open cyeb opened this issue 12 years ago • 12 comments

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.

cyeb avatar Jun 08 '14 05:06 cyeb

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

mitsuhiko avatar Jun 08 '14 16:06 mitsuhiko

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

untitaker avatar Jun 08 '14 17:06 untitaker

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.

cyeb avatar Jun 09 '14 14:06 cyeb

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.

mitsuhiko avatar Jun 09 '14 20:06 mitsuhiko

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

untitaker avatar Jun 14 '14 19:06 untitaker

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.

aldanor avatar Jul 03 '14 15:07 aldanor

:+1:

saad-cliqr avatar Mar 23 '16 10:03 saad-cliqr

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

izakp avatar Apr 06 '17 18:04 izakp

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.

gitlines avatar Jan 05 '18 19:01 gitlines

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.

awfki avatar Apr 23 '18 16:04 awfki

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

untitaker avatar Apr 24 '18 09:04 untitaker

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

davidism avatar May 14 '18 19:05 davidism