def construct_action(self, instance, spec, loc, context, action):
"""
Construct a command based on a specific actions, e.g. list,
create, etc.
"""
assert len(loc) == 4
self.init_adapter_conf(instance)
collection = loc[0] + '/' + loc[-3]
command = self.COMMANDS[action](self.clients.get(collection))
if action in self.RESOURCE_ACTIONS:
command = click.argument('resource_id')(command)
if action in self.CRITICAL_ACTIONS:
option = click.option(
'--yes', is_flag=True, callback=abort_if_false,
expose_value=False,
prompt='Are you sure you want to perform this action?')
command = option(command)
self._add_format_option(command, action)
instance[self.ADAPTER_CONF][action] = command
return instance
评论列表
文章目录