def complete(self, sp_args, line, rl_prefix, rl_begidx, rl_endidx):
        """
        Override in order to have command or argument completion.

        It is necessary to return a 'list', i.e. not a tuple or other
        sequences.
        """
        # TODO: Optionally check that flags are not repeated (i.e. exclude
        #       them from the possible matches if they are already in the
        #       command line)
        # TODO: Support groups of mutually-exclusive flags, i.e. if one is
        #       already present, the others in the group are not accepted
        if len(sp_args) == 0 or not line.endswith(sp_args[-1]):
            # if line.endswith(sp_args[-1]) is False, it means that the last
            # sp_args is already complete
            return self.accepted_flags
        else:
            matches = []
            for arg in self.accepted_flags:
                if arg.startswith(sp_args[-1]):
                    matches.append(arg)
            if len(matches) == 1:
                # In general, SPLIT_ARGS and readline use different word
                #  delimiters, see e.g. the docs for
                #  readline.get_completer_delims()
                # If for example there's a 'foo-bar' argument, SPLIT_ARGS sees
                #  it as a single word, but readline by default will split it
                #  in two words, 'foo' and 'bar', and if 'foo-b' is entered in
                #  the command line, and Tab is pressed, the word will be
                #  completed as 'foo-bfoo-bar', unless we compensate here by
                #  subtracting the rl_prefix from the found match
                sub = len(sp_args[-1]) - len(rl_prefix)
                return [matches[0][sub:]]
            else:
                return matches
def complete ( self , sp_args , line , rl_prefix , rl_begidx , rl_endidx ) : if len ( sp_args ) == 0 or not line . endswith ( sp_args [ - 1 ] ) : return self . accepted_flags else : matches = [ ] for arg in self . accepted_flags : if arg . startswith ( sp_args [ - 1 ] ) : matches . append ( arg ) if len ( matches ) == 1 : sub = len ( sp_args [ - 1 ] ) - len ( rl_prefix ) return [ matches [ 0 ] [ sub : ] ] else : return matches
Override in order to have command or argument completion.

        It is necessary to return a 'list', i.e. not a tuple or other
        sequences.