Fix group arguments in click (#561)

This commit is contained in:
eugen-ajechiloae-clearml 2022-02-12 00:01:44 +02:00 committed by GitHub
parent a47f127679
commit c01e2e1166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -66,15 +66,15 @@ class PatchClick:
@staticmethod
def _command_init(original_fn, self, *args, **kwargs):
if self and isinstance(self, Command) and 'name' in kwargs:
PatchClick._num_commands += 1
if running_remotely():
pass
else:
if isinstance(self, (Command, Group)) and 'name' in kwargs:
if isinstance(self, Command):
PatchClick._num_commands += 1
if not running_remotely():
name = kwargs['name']
if name:
PatchClick._args[name] = False
PatchClick._args_type[name] = PatchClick._command_type
if isinstance(self, Command):
PatchClick._args_type[name] = PatchClick._command_type
# maybe we should take it post initialization
if kwargs.get('help'):
PatchClick._args_desc[name] = str(kwargs.get('help'))
@ -108,7 +108,7 @@ class PatchClick:
ret = original_fn(self, *args, **kwargs)
if isinstance(self, Command) and not isinstance(self, Group):
if isinstance(self, Command):
ctx = kwargs.get('ctx') or args[0]
if running_remotely():
PatchClick._load_task_params()
@ -118,7 +118,8 @@ class PatchClick:
ctx.params[p.name] = p.process_value(
ctx, cast_str_to_bool(value, strip=True) if isinstance(p.type, BoolParamType) else value)
else:
PatchClick._args[self.name] = True
if not isinstance(self, Group):
PatchClick._args[self.name] = True
for k, v in ctx.params.items():
# store passed value
PatchClick._args[self.name + '/' + str(k)] = str(v or '')

View File

@ -3,9 +3,12 @@ from clearml import Task
@click.group()
def cli():
task = Task.init(project_name='examples', task_name='click multi command')
print('done')
@click.option('--print-something/--dont-print-something', default=True)
@click.option('--what-to-print', default='something')
def cli(print_something, what_to_print):
Task.init(project_name='examples', task_name='click multi command')
if print_something:
print(what_to_print)
@cli.command('hello', help='test help')
@ -15,7 +18,6 @@ def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
click.echo("Hello {}!".format(name))
print('done')
CONTEXT_SETTINGS = dict(