Skip to content

Add complete script generator #427

Description

@Toeger

argparse::ArgumentParser knows all possible arguments. It should therefore be possible to add a function argparse::ArgumentParser::generate_complete_script(command_name, shell) that generates a complete script which allows elaborate tab completion for the given command's arguments in the given shell.

See https://www.gnu.org/software/bash/manual/bash.html#A-Programmable-Completion-Example for an example of a complete script. The example is for bash specifically. Other terminals have other ways to complete, but it should be one that other terminals support the scripts of to also provide tab-completion.

To support this well, it makes sense to add an option .file() similar to the existing .required() to specify that an option expects an existing file name, which will then result in the appropriate complete script syntax which then makes bash complete existing files. .choices also lends itself well to tab-completion.

git is an example of a program that does this and it's very neat. git + tab will show a list of subcommands and git add + tab shows a list of files that can be added. If you use the terminal fish the completion is even better (showing only files that make sense to add, not all files for example) because it allows for full dynamic scripting instead of just a fixed set of options. Powershell is probably also worth supporting.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions