Closed teto closed 5 years ago
We have always used it like the first way you tried to do it, except we combine the add_argument
call inside the setattr
. Here is an example from within cmd2 itself where we are setting up path completion for a positional argument to the create subcommand of the alias command:
setattr(alias_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
help='arguments to pass to command'),
ACTION_ARG_CHOICES, ('path_complete',))
@kmvanbrunt Now that I think about it, can you take a look at how we use path_complete
in the tab_autocompletion.py and tab_autocomp_dynamic.py examples, I think we forgot to update those examples when the signature changed.
@tleonhardt I fixed the examples.
@teto Have you been able to resolve your issue?
not sure what happened since I changed nothing since Friday but the autocompletion seems to work again :) thanks
the signature for path_complete changed in 0.9.7
path_filter: Optional[Callable[[str], bool]] = None) -> List[str]:
I tried to update my code but I have lost the autocompletion, everytime I press TAB, I just get the help:
I used to add filename autocompletion via
I tried to change it to
setattr(load_pcap, argparse_completer.ACTION_ARG_CHOICES, ('path_complete', ))
orsetattr(load_pcap, argparse_completer.ACTION_ARG_CHOICES, ('path_complete', lambda x=True))
without success. What 's the correct upgrade ?