I would like to add unspecified options to the cli command using python-click library. So my cli function could look like the following
$ my-cmd --option1 value1 --options2 value2 --unknown_var value3
My current code:
import click
@click.option('--option1')
@click.option('--option2')
@click.command(name='my-cmd')
def cli(option1, option2):
click.echo("my test")
I would like to see something like the following:
import click
@click.option('--option1')
@click.option('--option2')
@click.command(name='my-cmd')
def cli(option1, option2, **kwargs):
click.echo("my test")
# Manually manage **kwargs
You can pass
context
withignore_unknown_options
andallow_extra_args
settings, the extra arguments will be collected incontext.args
list (['--unknown_var', 'value3', '--unknown_var2', 'value4']
). Then you can transform it to dict.example
See Forwarding Unknown Options.