Expected Behavior:
if You have a group with arguments, and You want to get help for a sub-command,
You must not ask to fill in the arguments for the group.
That prevents me to create an automated documentation for all the commandline options of a program.
This forces the User to put in arguments for the group (what he might not be able to state correctly, because those arguments are checked for instance if the file is existing, etc ...) in order to get help for the sub-command.
# EXT
import click
# CONSTANTS
CLICK_CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
CLICK_CONTEXT_SETTINGS_NO_HELP = dict(help_option_names=[])
@click.group(help='some help', context_settings=CLICK_CONTEXT_SETTINGS)
@click.version_option(version='1.1.1',
prog_name='program name',
message='{} version %(version)s'.format('cli command'))
def cli_main() -> None: # pragma: no cover
pass # pragma: no cover
# command1 without arguments and options
@cli_main.command('command1', context_settings=CLICK_CONTEXT_SETTINGS_NO_HELP)
def cli_command1() -> None: # pragma: no cover
""" command1 without arguments and options """
pass
# command4 with arguments, options and sub_command
# groups must not have arguments or we can not parse them
# because to get help for the sub command we need to put :
# program command4 arg1 arg2 command5 -h
# and we dont know the correct type of arg1, arg2 at parsing time
@cli_main.group('command4', context_settings=CLICK_CONTEXT_SETTINGS)
@click.argument('argument1')
@click.argument('argument2')
@click.option('-a', '--a_option', is_flag=True) # no help here
@click.option('-b', '--b_option', type=int, default=-1, help='help for b_option')
@click.option('-c', '--c_option', help='help for c_option')
def cli_command4(argument1: str, argument2: str, a_option: bool, b_option: int, c_option: str) -> None:
"""command4 with arguments, options and sub_command"""
pass # pragma: no cover
# command5, sub_command of command4 with arguments, options
@cli_command4.command('command5', context_settings=CLICK_CONTEXT_SETTINGS)
@click.argument('argument1')
@click.argument('argument2')
@click.option('-a', '--a_option', is_flag=True) # no help here
@click.option('-b', '--b_option', type=int, default=-1, help='help for b_option')
@click.option('-c', '--c_option', help='help for c_option')
def cli_command5(argument1: str, argument2: str, a_option: bool, b_option: int, c_option: str) -> None:
"""command5, sub_command of command4 with arguments, options"""
pass # pragma: no cover
# entry point if main
if __name__ == '__main__':
cli_main()
Actual Behavior
if You want to get help for command5 You need to put :
# You need to put (current behaviour):
$> cli_program command4 arg1 arg2 command5 -h
# You should be able to put (expected behaviour):
$> cli_program command4 command5 -h
furthermore, it seems the stated error is wrong:
$> cli_program command4 command5 -h
Usage: test_cli_help.py command4 [OPTIONS] ARGUMENT1 ARGUMENT2 COMMAND
[ARGS]...
Try 'test_cli_help.py command4 -h' for help.
Error: Missing command. # shouldnt this be "Missing argument." ???
You probably dont want (or can not) fill arg1, arg2 because arg1, arg2 might be files what needs to be present, and so on ...
I guess You need to skip to check for the presence of arguments of the group, if the help option is detected, as You do it for the normal click.command
Expected Behavior:
if You have a group with arguments, and You want to get help for a sub-command,
You must not ask to fill in the arguments for the group.
That prevents me to create an automated documentation for all the commandline options of a program.
This forces the User to put in arguments for the group (what he might not be able to state correctly, because those arguments are checked for instance if the file is existing, etc ...) in order to get help for the sub-command.
Actual Behavior
if You want to get help for command5 You need to put :
furthermore, it seems the stated error is wrong:
You probably dont want (or can not) fill arg1, arg2 because arg1, arg2 might be files what needs to be present, and so on ...
I guess You need to skip to check for the presence of arguments of the group, if the help option is detected, as You do it for the normal click.command