1

I am trying to build a cli with 2 sets of arguments using the Click extension click_option_group (https://github.com/click-contrib/click-option-group) . One group is the "server Configuration" and I can use the "option" with it for the "name". In the other group "My app Configuration", I want to use "argument". Can I use "argument" with optgroup for "app". So users can just pass a apps as arguments. I get an error "'_Optgroup' object has no attribute 'argument' " Is there a way to pass argument in optgroup ?

Here's the code:


import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup, OptionGroup

@click.command()
@click.option('--outfile', '-o')
@optgroup.group('Server  configuration', help='The configuration for Server')
@optgroup.option('--name', '-n', help='Server host name')

@optgroup.option('My app configuration', cls=RequiredMutuallyExclusiveOptionGroup, help='The configuration for my app')
@optgroup.argument('app',  nargs=-1)


def cli(**params):
    print(params)

def data(*args):
    for a in args:
        click.echo(a)

if __name__ == '__main__':
    cli()
RDs
  • 513
  • 6
  • 22
  • I don't think what you are trying to do is possible, but I'm not sure I understand it. If you can explain in more detail what you want to accomplish, you may get a better answer. – Dennis Sparrow Jun 08 '20 at 23:59
  • I updated the question, hope that helps. I am trying to do something similar to here https://stackoverflow.com/questions/34643620/how-can-i-split-my-click-commands-each-with-a-set-of-sub-commands-into-multipl . But using the click_option_group and without any extra files. – RDs Jun 09 '20 at 14:49
  • As you have found, there is no such thing as `@optgroup`.argument. You could try `@click.argument`, but I think the optgroup will reject it. I don't see how you can do better than to specify `@click.argument` outside any group. – Dennis Sparrow Jun 09 '20 at 15:29

0 Answers0