Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argcomplete-like tab completion #261

Open
con-f-use opened this issue Feb 22, 2015 · 7 comments
Open

Argcomplete-like tab completion #261

con-f-use opened this issue Feb 22, 2015 · 7 comments

Comments

@con-f-use
Copy link

A feature I would very much like to see is tab completion as in e.g. provided by argcomplete for argparse.

E.g. for the usage string Usage: myprog.py (add | delete) <item>, the used would only have to type ./myprog.py de and press TAB to complete this to ./myprog.py delete.

@keleshev
Copy link
Member

There is a package like that somewhere, I remember, but I don't remember its name and searching for docopt complete on PyPI does not yield results.

@BurntSushi
Copy link
Member

There is tool bundled with docopt.rs: https://github.com/docopt/docopt.rs#tab-completion-support --- But I haven't gotten around to distributing binaries yet, so you'd have to install Rust and compile it. But then you should be able to use it with any Docopt implementation.

@con-f-use
Copy link
Author

Oh wow, and once again, you just have to ask and the internet gives... It seems to work.

As much as I appreciate this tool, eventually there should be native support for tab completion in docopt. The simple reason being, if I were to ship my application, I would have to include Rust, cargo and build the tab completion tool on the target system. All that with no guaratee that it works and a lot of overhead.

@keleshev
Copy link
Member

@con-f-use
Copy link
Author

Thank you two! After closer inspection, I found a few quirks with both and reported them. I, however, like docopt.rs's meachanism better. That is mainly because it has fewer and more tollerable bugs and it generates the completions on the fly, every time when requested. That allows for commands and options changing dynamically, e.g. by config-file. So the docopt_wordlist from docopt.rs should suit most needs. Still annoying that you can't install it with pip or something similar, I hope you get around to distribution binaries soon.

@con-f-use
Copy link
Author

On a usability note, maybe docopt_wordlist should be incorporated directly into the docopt module as a hidden option. What I mean is a script using docopt with:
Usage: myscript FILE [--port | --poster | --potential]
Could be called with:
./script.py --__word-list__ "script.py foobar --po"
Where --__word-list__ is a hidden option. When run with the option and the cword arument (here foobar --po), the script will spit out the possible completions for --po*, namely:
--port --potential --poster
That hidden option can den be used in a Bash completion script.

I think such predictions should be generated fairly readily once you have
pattern = parse_pattern(formal_usage(DocoptExit.usage), options)
All of the inforation is in there. I didn't look close enough on how these nested pattern variable is constructed and what it would take to parse it, but a quick print pattern shows that all the options and their "either", "required", "takes argument", (etc.) status is in there.

@casperdcl
Copy link

If you just need a docstring to argparse module (based on docopt syntax but with a couple of extensions)... I have implemented a module called argopt (https://pypi.python.org/pypi/argopt#usage or https://github.com/casperdcl/argopt#usage)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants