Example #1
0
    def __init__(self, yamls, c, parent=None, pos=0):
        self.pos = pos

        if not c:
            # used only for root node
            self.name = ""
            self.cname = "root"
            self.summary = ""
            self.type = CD_TYPE_GROUP
            return

        if not c.get("name") or not c.get("summary"):
            print("No `name`/`summary` fields in", c)
            sys.exit(1)

        # RzCmdDesc fields
        self.name = c.pop("name")
        self.cname = c.pop("cname", None) or compute_cname(self.name)
        self.type = None
        self.parent = parent
        self.subcommands = None
        self.exec_cd = None
        self.modes = c.pop("modes", None)
        self.handler = c.pop("handler", None)
        self.default_mode = c.pop("default_mode", None)
        # RzCmdDescHelp fields
        self.summary = strip(c.pop("summary"))
        self.description = strip(c.pop("description", None))
        self.args_str = strip(c.pop("args_str", None))
        self.usage = strip(c.pop("usage", None))
        self.options = strip(c.pop("options", None))
        self.sort_subcommands = c.pop("sort_subcommands", None)

        self.details = None
        self.details_alias = None
        self.details_cb = None
        self._process_details(c)

        self.args = None
        self.args_alias = None
        self._process_args(c)

        # determine type before parsing subcommands, so children can check type of parent
        self._set_type(c)

        self._set_subcommands(c, yamls)

        self._validate(c)
        CmdDesc.c_cds[self.cname] = self
        if self.get_handler_cname():
            CmdDesc.c_handlers[self.get_handler_cname()] = self
        if self.args:
            CmdDesc.c_args[CmdDesc.get_arg_cname(self)] = self
        if self.details:
            CmdDesc.c_details[CmdDesc.get_detail_cname(self)] = self
Example #2
0
def find_c_name_handler(basedir, rzcommand):
    for f in get_yaml_files(basedir):
        with open(f, "r", encoding="utf8") as of:
            y = yaml.safe_load(of)
            e = find_entry(y["commands"], rzcommand)
            if e is not None:
                cname = e.get("cname", compute_cname(e["name"]))
                return get_handler_cname(
                    e.get("type", None), e.get("handler", None), cname
                )

    return None
Example #3
0
 def get_detail_entries_cname(self):
     return self.cd.cname + "_" + compute_cname(self.name) + "_detail_entries"
Example #4
0
    def _get_choices_cname(self):
        if self.type == "RZ_CMD_ARG_TYPE_CHOICES":
            return self.cd.cname + "_" + compute_cname(self.name) + "_choices"

        raise Exception("_get_choices_cname should be called on ARG_TYPE_CHOICES only")