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
...
Currently
argparsehas a standard mechanism to specify what type to complete (thetypeargument toadd_argument), but doesn't have a mechanism to specify what it is intended to complete with the exception ofFileType.pyzshcompleteshould supply custom types that will allow it to make better choice of what is to be completed.Suggestion:
which can be used like this:
Then we can change the
complete_withfunction to do something like this: