Esempio n. 1
0
def complete_machine(
        self,
        running=None,
        active=None,
        term_or_reset=None) -> List[cmd2.argparse_custom.CompletionItem]:
    """ Return a list of CompletionItems for machines """
    result = []
    for m in self.cnxn.machines:
        # Match active
        if active is not None and m.expired == active:
            continue
        # Match running
        if running is not None and m.spawned != running:
            continue
        # Match terminating or resetting
        if term_or_reset is not None and not m.terminating and not m.resetting:
            continue

        if m.resetting:
            state = "resetting"
        elif m.terminating:
            state = "terminating"
        elif m.spawned:
            state = m.expires
        else:
            state = "stopped"

        os = f"{HackTheBox.OS_ICONS.get(m.os.lower(), HackTheBox.OS_ICONS['other'])} {m.os}"
        result.append(
            cmd2.CompletionItem(m.name.lower(), f"{os:<13}{m.ip:<13}{state}"))

    return result
Esempio n. 2
0
    def extras_choices_method(self):
        """Method that returns all possible values for the 'extras' command, used for tab-completion."""
        completions_with_desc = []

        extras_keys = self._current_node.extras_keys()
        for key in extras_keys:
            completions_with_desc.append(
                cmd2.CompletionItem(
                    key, "({})".format(
                        type(self._current_node.get_extra(key)).__name__)))

        # Mark that we already sorted the matches
        # self.matches_sorted = True
        return completions_with_desc
Esempio n. 3
0
    def attrs_choices_method(self):
        """Method that returns all possible values for the 'attrs' command, used for tab-completion."""
        completions_with_desc = []

        attributes_keys = self._current_node.attributes_keys()
        for key in attributes_keys:
            #if key.startswith(text):
            completions_with_desc.append(
                cmd2.CompletionItem(
                    key, "({})".format(
                        type(self._current_node.get_attribute(key)).__name__)))

        # Mark that we already sorted the matches
        # self.matches_sorted = True
        return completions_with_desc