mirror of
https://github.com/clearml/clearml
synced 2025-02-12 07:35:08 +00:00
Fix group arguments in click (#561)
This commit is contained in:
parent
a47f127679
commit
c01e2e1166
@ -66,14 +66,14 @@ 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:
|
||||||
|
if isinstance(self, Command):
|
||||||
PatchClick._num_commands += 1
|
PatchClick._num_commands += 1
|
||||||
if running_remotely():
|
if not running_remotely():
|
||||||
pass
|
|
||||||
else:
|
|
||||||
name = kwargs['name']
|
name = kwargs['name']
|
||||||
if name:
|
if name:
|
||||||
PatchClick._args[name] = False
|
PatchClick._args[name] = False
|
||||||
|
if isinstance(self, Command):
|
||||||
PatchClick._args_type[name] = PatchClick._command_type
|
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'):
|
||||||
@ -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,6 +118,7 @@ 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:
|
||||||
|
if not isinstance(self, Group):
|
||||||
PatchClick._args[self.name] = True
|
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
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user