click-default-group icon indicating copy to clipboard operation
click-default-group copied to clipboard

Missing command error when providing only group options

Open edobez opened this issue 4 years ago • 2 comments

As title says, a missing command error is shown when only group options are passed to the prompt.

The expected behavior is that group options are handled by the group and then default command is invoked.

Minimum example

import click
from click_default_group import DefaultGroup

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
@click.option('-v', is_flag=True)
def cli(v):
    print('cli group exec')
    if v:
        print('Verbose!')

@cli.command()
@click.option('--config')
def foo(config):
    print('foo command exec')
    if config:
        print(f'config={config}')

Execution

$ program foo                           
--> normal call, works

$ program
--> default cmd is called, works

$ program --config=abc 
--> option is forwarded to 'foo' cmd, works

$ program -v --config=abc
--> '-v' option is parsed by group and '--config' is parsed by 'foo' cmd, works

$ program -v
--> doesn't work!

edobez avatar May 08 '21 08:05 edobez

I forked and created a branch with (refactored) tests covering this behavior. I looked a bit into it but didn't find a proper solution yet.

edobez avatar May 08 '21 14:05 edobez

I've pushed fix #23. Hope this patch is in line with plans of author. @sublee

pyhedgehog avatar Oct 27 '22 19:10 pyhedgehog