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

View File

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