pyzshcomplete
pyzshcomplete copied to clipboard
Supply custom argparse types for better completion
Currently argparse has a standard mechanism to specify what type to complete (the type argument to add_argument), but doesn't have a mechanism to specify what it is intended to complete with the exception of FileType.
pyzshcomplete should supply custom types that will allow it to make better choice of what is to be completed.
Suggestion:
class ArgparsePidCompleter:
COMPLETE_WITH = 'pids'
def __call__(self, string):
return int(string)
which can be used like this:
parser.add_argument('pid', type=ArgparsePidCompleter())
Then we can change the complete_with function to do something like this:
@property
def complete_with(self):
...
try:
return self._argument.type.COMPLETE_WITH
except:
pass
...