def run(self): parser = Parser() categories = copy.copy(main.categories) categories["db"] = manage.DBCommands cliutils._add_command_parsers(categories, parser) content = [] for category in sorted(categories.keys()): content.append(make_category_section( category, parser.parsers[category]["parser"])) return content
def run(self): parser = Parser() categories = copy.copy(main.categories) categories["db"] = manage.DBCommands cliutils._add_command_parsers(categories, parser) content = [] for category in sorted(categories.keys()): content.append( make_category_section(category, parser.parsers[category]["parser"])) return content
def run(self): parser = Parser() categories = copy.copy(main.categories) if "group" in self.options: categories = {k: v for k, v in categories.items() if k == self.options["group"]} cliutils._add_command_parsers(categories, parser) content = [] for cg in sorted(categories.keys()): content.append(make_category_section( cg, parser.parsers[cg]["parser"])) return content
def run(self): parser = Parser() categories = copy.copy(main.categories) if "group" in self.options: categories = { k: v for k, v in categories.items() if k == self.options["group"] } cliutils._add_command_parsers(categories, parser) content = [] for cg in sorted(categories.keys()): content.append( make_category_section(cg, parser.parsers[cg]["parser"])) return content
def discover_cli(): categories = [] parser = Parser() raw_categories = copy.copy(rally_cli_main.categories) cliutils._add_command_parsers(raw_categories, parser) for cg in sorted(raw_categories.keys()): if cg == "deployment": # oops. let's skip it continue cparser = parser.parsers[cg]["parser"] # NOTE(andreykurilin): we are re-using `_add_command_parsers` # method from `rally.cli.cliutils`, but, since it was designed # to print help message, generated description for categories # contains specification for all sub-commands. We don't need # information about sub-commands at this point, so let's skip # "generated description" and take it directly from category # class. description = cparser.defaults["command_object"].__doc__ commands = [] for command in sorted(cparser.subparser.parsers.keys()): subparser = cparser.subparser.parsers[command] arguments = [] defaults = utils.get_defaults( subparser["parser"].defaults["action_fn"]) for args, kwargs in subparser["parser"].arguments: # for future changes... # :param args: a single command argument which can represented # by several names(for example, --uuid and --task-id) in cli # :type args: tuple # :param kwargs: description of argument. Have next format: # {"dest": "action_kwarg_<name of keyword argument in code>", # "help": "just a description of argument" # "metavar": "[optional] metavar of argument." # "Example: argument '--file'; metavar 'path' ", # "type": "[optional] class object of argument's type", # "required": "[optional] boolean value"} # :type kwargs: dict argument = { "dest": kwargs.get("dest").replace("action_kwarg_", ""), "args": args, "metavar": kwargs.get("metavar"), "description": kwargs.get("help", ""), } action = kwargs.get("action") if not action: arg_type = kwargs.get("type") if arg_type: argument["type"] = arg_type.__name__ skip_default = argument["dest"] in ("deployment", "env", "task_id", "verification") if not skip_default and argument["dest"] in defaults: argument["defaults"] = defaults[argument["dest"]] arguments.append(argument) commands.append({ "name": "rally %s %s" % (cg, command), "command": command, "description": subparser["description"], "arguments": arguments }) categories.append({ "name": cg, "description": description, "commands": commands }) data = {"categories": categories, "rally": version.version_string()} with open(CLI_SOURCE, "w") as f: f.write(json.dumps(data, indent=4)) return data