nargs=* equivalent for options in Click

One way to approach what you are after is to inherit from click.Option, and customize the parser. Custom Class: import click class OptionEatAll(click.Option): def __init__(self, *args, **kwargs): self.save_other_options = kwargs.pop(‘save_other_options’, True) nargs = kwargs.pop(‘nargs’, -1) assert nargs == -1, ‘nargs, if set, must be -1 not {}’.format(nargs) super(OptionEatAll, self).__init__(*args, **kwargs) self._previous_parser_process = None self._eat_all_parser = … Read more

Click Command Line Interfaces: Make options required if other optional option is unset

This can be done by building a custom class derived from click.Option, and in that class over riding the click.Option.handle_parse_result() method like: Custom Class: import click class NotRequiredIf(click.Option): def __init__(self, *args, **kwargs): self.not_required_if = kwargs.pop(‘not_required_if’) assert self.not_required_if, “‘not_required_if’ parameter required” kwargs[‘help’] = (kwargs.get(‘help’, ”) + ‘ NOTE: This argument is mutually exclusive with %s’ % … Read more