click-contrib/click-default-group

Missing command error when providing only group options

edobez opened this issue · 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!

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.

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