Skip to content

Supply custom argparse types for better completion #15

@dan1994

Description

@dan1994

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
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNew feature or requestHelp WantedExtra attention is neededPythonRelated to the python code generating completions

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions