class OptionPromptNull(click.Option):
_value_key = '_default_val'
def get_default(self, ctx):
if not hasattr(self, self._value_key):
default = super(OptionPromptNull, self).get_default(ctx)
setattr(self, self._value_key, default)
return getattr(self, self._value_key)
def prompt_for_value(self, ctx):
default = self.get_default(ctx)
# only prompt if the default value is None
if default is None:
return super(OptionPromptNull, self).prompt_for_value(ctx)
return default
Usage:
@click.command()
@click.option('--tenant', '-t', cls=OptionPromptNull, default=Config.TENANT_NAME, prompt='Please enter tenant name', help='MindSphere tenant name')
@click.option('--client_id', '-ci', cls=OptionPromptNull, default=Config.CLIENT_ID, prompt='Please enter client id', help='MindSphere service account client id')
@click.option('--client_secret', '-cs', hide_input=True, cls=OptionPromptNull, default=Config.CLIENT_SECRET, prompt='Please enter client secret (it will be hidden while you type & kept secretly)', help='MindSphere service account client secret')
@click.option('--key', '-k', cls=OptionPromptNull, default=Config.ENCRYPTION_KEY, prompt='Please enter any secret key', help='Secret key used to store sensitive information in encrypted format ')
@click.option('--config_file', '-cf', cls=OptionPromptNull, default=Config.DEFAULT_CONFIG_FILE, prompt='Please enter config file path', help='Specific config file to execute MindSphere tasks')
def setup(tenant, client_id, client_secret, key, config_file):
pass
@click.group()
def cli():
pass