示例#1
0
    def get_tool_name(self):
        num_args = len(self.arg_list)
        err.assert_abort(num_args >= 2,
                         f"ERROR: minimum # of args is 2, got '{num_args}'",
                         True)

        first_arg = 0
        first_value = 1
        if self.arg_list[first_arg] == "-tool":
            # Check next arg and see if it is a value or another arg name
            if self.arg_list[first_value][
                    0] != '-':  # A '-' would indicate another argument name, not a value
                name = self.arg_list[first_value]
                # Remove the tool flag and value from the arg_list (tool creation won't need it)
                self.arg_list.pop(0)
                self.arg_list.pop(
                    0)  # 0 again because you just popped the previous 0 item.
                return name
            else:
                err.error_abort(
                    f"ERROR: Tool name has '-' in it '{self.arg_list[first_value]}'",
                    True)
        else:
            err.error_abort(
                f"ERROR: Incorrect syntax: '{err.get_script_call_string()}'",
                True)
    def validate_arguments(self, name_list, value_name_list, optional_name_list, optional_value_list):
        # Make all names lower case (do not change values)
        for local_list in (name_list, value_name_list, optional_name_list, optional_value_list):
            index = 0
            while index < len(local_list):
                local_list[index] = local_list[index].lower()
                index += 1

        for name in name_list:
            err.assert_abort(name in self.arg_names,
                             f"ERROR: '{name}' is a required argument", True)
        for name in value_name_list:
            err.assert_abort(name in self.arg_pairs,
                             f"ERROR: '{name}' requires a value", True)
        # Optional name list is a bit trickier.  Need to remove all required names first then compare
        # each optional name to the optional list.  I.e. are the non-required names in the list 'allowed'
        # by the optional list?
        remaining_names = []
        for name in self.arg_names:
            if name not in name_list:
                remaining_names.append(name)
        for name in remaining_names:
            err.assert_abort(name in optional_name_list,
                             f"ERROR: '{name}' is not a valid argument", True)
            # Is a valid optional arg.  If also in optional_value_list then it must have a value
            if name in optional_value_list:
                err.assert_abort(name in self.arg_pairs,
                                 f"ERROR: '{name}' requires a value", True)