def get_command(self, ctx, cmd_name): """ gets the Click Commands underneath a service name Parameters ---------- ctx: Context context object passed in cmd_name: string the service name Returns ------- cmd: Click.Command the Click Commands that can be called from the CLI """ if cmd_name not in self.subcmd_definition: return None parameters = [] for param_name in self.subcmd_definition[cmd_name][self.TAGS].keys(): default = self.subcmd_definition[cmd_name][ self.TAGS][param_name]["default"] parameters.append( click.Option( ["--{}".format(param_name)], default=default, help= "Specify the {} name you'd like, otherwise the default = {}" .format(param_name, default), )) command_callback = functools.partial(self.cmd_implementation, self.events_lib, self.top_level_cmd_name, cmd_name) config = get_ctx_defaults( cmd_name=cmd_name, provider=TomlProvider(section="parameters"), ctx=ctx, config_env_name=samconfig.DEFAULT_ENV, ) cmd = click.Command( name=cmd_name, short_help=self.subcmd_definition[cmd_name]["help"], context_settings={"default_map": config}, params=parameters, callback=command_callback, ) cmd = debug_option(cmd) return cmd
def get_command(self, ctx, cmd_name): """ gets the Click Commands underneath a service name Parameters ---------- ctx: Context context object passed in cmd_name: string the service name Returns ------- cmd: Click.Command the Click Commands that can be called from the CLI """ if cmd_name not in self.subcmd_definition: return None parameters = [] for param_name in self.subcmd_definition[cmd_name][self.TAGS].keys(): default = self.subcmd_definition[cmd_name][self.TAGS][param_name]["default"] parameters.append(click.Option( ["--{}".format(param_name)], default=default, help="Specify the {} name you'd like, otherwise the default = {}".format(param_name, default) )) command_callback = functools.partial(self.cmd_implementation, self.events_lib, self.top_level_cmd_name, cmd_name) cmd = click.Command(name=cmd_name, short_help=self.subcmd_definition[cmd_name]["help"], params=parameters, callback=command_callback) cmd = debug_option(cmd) return cmd