click
click copied to clipboard
Invoking a command does not fail on missing arguments
If I invoke a command with an required argument (nargs=1) from within another one without passing the argument it still works. None is passed as default, although I do no set some. If I invoke the callback I get the expected exception.
Short example
import click
@click.group()
def group():
pass
@group.command()
@click.argument("arg", nargs=1, required=True)
def withparam(arg):
print(
f"INVOKED with argument {arg}"
)
@group.command()
def withoutparam():
print(f"RUNNING without params")
click.get_current_context().invoke(withparam)
if __name__ == "__main__":
group()
Result is:
> python test.py withoutparam
RUNNING without params
INVOKED with argument None
Is this intended?
Environment:
- Python version: 3.13
- Click version: 8.1.7
This is intended and somewhat documented in the options section. I will add it to the arguments section explicitly.