Infinidat / infi.docopt_completion

BSD 3-Clause "New" or "Revised" License
109 stars 9 forks source link

docopt_completion doesn't seem to honor mandatory arguments #9

Open con-f-use opened 9 years ago

con-f-use commented 9 years ago

The module does not seem to fully honor mandatory backets (-option) and ignores commands therein.

Example code:

#!/usr/bin/env python
"""Demonstration of docopt_completion not honoring exclusives.

Usage:
    exhon.py --help
    exhon.py (-c cmd)

Options:
  -h      Print help
  -c     Indicats command mode
"""
from docopt import docopt
arguments = docopt(__doc__)
print arguments

Expected behavior in bash session:

confus@confusion:~/test$ exhon.py #[TAB]
-c         --help
confus@confusion:~/test$ exhon.py -c #[TAB] completes to only allowed commad:
confus@confusion:~/test$ exhon.py -c cmd

Actual (wrong) behavior in bash session:

confus@confusion:~/test$ exhon.py #[TAB] gives wrong selection ("cmd" should not be there)
-c         cmd    --help
confus@confusion:~/test$ exhon.py -c #[TAB] gives no completion (should complete to "... -c cmd")
confus@confusion:~/test$ exhon.py -c

Arranging the usage string the other way around as in exhon.py (cmd -c) yields better but similarly wrong results:

confus@confusion:~/test$ exhon.py cmd#[TAB] completes as expected to:
confus@confusion:~/test$ exhon.py cmd -c#[TAB] but further tab repeats the option:
confus@confusion:~/test$ exhon.py cmd -c -c # again and again if [TAB] is pressed more often
wiggin15 commented 9 years ago

This works correctly in zsh, but not yet in bash. The completion system in bash is not as good as zsh's, so I put less effort trying to make it work perfectly there. I'll leave this open but I don't know if I'll get around to fixing this in bash (help is welcome :))

con-f-use commented 9 years ago

Okay, thank you. In the unlikely event I have time to spare, I'll have a look. I hope you get around to it. In the meantime you should add a note about known issues in bash. After all bash is by far the more common shell and should be priority.

Btw. there is a very similar tool called docopt-wordlist out for Rust: https://github.com/docopt/docopt.rs#tab-completion-support Its main advantage is, that it generates the completions on the fly, so it reacts to changes in the program withou rerunning the tool. That also allows for generation options dynamically (e.g. based on a configuration file or plugin files to the original program using docopt). Its downside is, that you have to install Rust and cargo on the target system, compile the tool while with docopt_completion one only has to provide the generated completion script with one's program. Ideally docopt_completion makes both approaches possible.