Commit 42108fc5 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

[script][click_helper] Add entries information when ResourceOptions are used

parent 66df3b55
from ..log import set_verbosity_level from ..log import set_verbosity_level
from ..config import load, mod_to_context from ..config import load, mod_to_context
from ..utils import resource_keys
import time import time
import click import click
import logging import logging
...@@ -171,11 +172,16 @@ def dump_config(command, params, ctx): ...@@ -171,11 +172,16 @@ def dump_config(command, params, ctx):
continue continue
if param.help is not None: if param.help is not None:
config_file.write('## %s.\n' % param.help) config_file.write('## %s.\n' % param.help)
dflt='' if (param.required or False) else \ dflt='' if param.required or (isinstance(param, ResourceOption) and
"[default: {}]".format(param.default) param.real_required) else \
"[default: {}]".format(param.default)
config_file.write( config_file.write(
'## Option: %s %s\n' % (', '.join(param.opts), dflt) '## Option: %s %s\n' % (', '.join(param.opts), dflt)
) )
if isinstance(param, ResourceOption) and param.entry_point_group is not\
None:
config_file.write("## registered entries are: {}\n".format(
resource_keys(param.entry_point_group)))
config_file.write('# %s = %s\n\n' % (param.name, config_file.write('# %s = %s\n\n' % (param.name,
str(ctx.params[param.name]))) str(ctx.params[param.name])))
...@@ -303,7 +309,6 @@ class ResourceOption(click.Option): ...@@ -303,7 +309,6 @@ class ResourceOption(click.Option):
while isinstance(value, basestring): while isinstance(value, basestring):
value = load([value], entry_point_group=self.entry_point_group) value = load([value], entry_point_group=self.entry_point_group)
value = getattr(value, keyword) value = getattr(value, keyword)
return value return value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment