mirror of
https://github.com/clearml/clearml
synced 2025-02-07 13:23:40 +00:00
Fix group arguments in click (#561)
This commit is contained in:
parent
a47f127679
commit
c01e2e1166
@ -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 '')
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user