question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

path_complete doesn't work with CommandSet

See original GitHub issue

Version 1.3.0.

When using path_complete for a CommandSet argparse argument the following exception occurs:

Traceback (most recent call last):
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/cmd2.py", line 1707, in complete
    self._completion_for_command(text, line, begidx, endidx, shortcut_to_restore)
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/cmd2.py", line 1592, in _completion_for_command
    self.completion_matches = self._redirect_complete(text, line, begidx, endidx, compfunc)
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/cmd2.py", line 1385, in _redirect_complete
    return compfunc(text, line, begidx, endidx)
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/cmd2.py", line 1757, in _complete_argparse_command
    return completer.complete_command(tokens_to_parse, text, line, begidx, endidx, cmd_set=cmd_set)
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/argparse_completer.py", line 429, in complete_command
    completion_results = self._complete_for_arg(pos_arg_state.action, text, line,
  File "/home/martin/.virtualenvs/pyos/lib/python3.8/site-packages/cmd2/argparse_completer.py", line 596, in _complete_for_arg
    results = arg_choices.to_call(*args, **kwargs)
TypeError: path_complete() takes 5 positional arguments but 6 were given

This happens because the CommandSet is being passed in as the second positional argument which isn’t expected by the completer.

A big benefit of completers is that they can be used by disparate commands (whether they be free functions later bound to a Cmd class, members of a Cmd class or members of a CommandSet). Having a different interface detracts from this as, now, something like a shim is required to make it work without redefining a new path_complete.

I think it’s worth considering ways to have a common interface, not only for the complete functions but for do and help. A couple of suggestions come to mind:

def path_complete(self, text: str, line: str, begidx: int, endidx: int, context)

where context is a dict or namedtuple that stores a reference to the Cmd instance and (optionally) the CommandSet.

Both Cmd and CommandSet conform to a common interface that specifies the subset of things that can be done by both (most methods/attributes from Cmd), and CommandSet just forwards these to its _cmd member.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
anselorcommented, Aug 6, 2020

I think since that’s causing some confusion, I’m going to rename the directory to tests_isolated so it’ll be grouped together and be more noticeable.

0reactions
anselorcommented, Aug 6, 2020

This was fixed in #968

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix: Command Prompt Tab to Autocomplete not working
Fix: Command Prompt Tab to Autocomplete not working ... via command-line, use the following reg.exe commands from a Command Prompt window:
Read more >
tab completion for commands not working · Issue #749 - GitHub
If i type git comm in bash, I cat hit TAB and either get the command completed for me. I'm sure many others...
Read more >
How do I get the directory where a Bash script is located from ...
+1, but the problem with using dirname $0 is that if the directory is the current directory, you'll get . . That's fine...
Read more >
Custom Sequence Commands - Pixel Crushers Forum
Enjoying the versatility of them but I've run into a problem I'm having trouble working through. I have two Custom Sequence Commands set...
Read more >
Understanding and Troubleshooting HSRP Problems ... - Cisco
Issue these commands in order to gather additional information about the problem: ... If there is a router on this path, complete these...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found