How do I do tab completion for a directory argument using argparse in cmd2?

142 Views Asked by At

I am using cmd2 to write an interactive Python application. I use the @with_argparser decorator for argument parsing. One of my do_ action arguments is a directory. I would like tab completion to suggest directories. I know how to set up tab completion in cmd2 by adding a complete_ member function, but I think that only works for do_ actions that do not use @with_argparser. How would I add tab completion to the following code?

class App(Cmd):
    ...
    parser = ArgumentParser()
    parser.add_argument('directory')
    @with_argparser(parser)
    def do_load_directory(self, args):
        ...
0

There are 0 best solutions below