iterative / shtab

↔️ Automagic shell tab completion for Python CLI applications
https://docs.iterative.ai/shtab
Other
362 stars 35 forks source link

bash: support -- delimeter #164

Closed casperdcl closed 5 months ago

casperdcl commented 6 months ago

diff sans whitespace

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.88%. Comparing base (c65c362) to head (3b40ff3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #164 +/- ## ======================================= Coverage 88.88% 88.88% ======================================= Files 3 3 Lines 360 360 ======================================= Hits 320 320 Misses 40 40 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

casperdcl commented 6 months ago

/CC @usidedown does this work for you?

pip install "git+https://github.com/iterative/shtab.git@double-dash#egg=shtab"
usidedown commented 6 months ago

Awesome, thanks for the quick response!

I'm getting a slight weirdness.

Here's my example:

import argparse

def get_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument('--opt1', choices=['a','b'])
    parser.add_argument('pos1', type=int, choices=list(range(8)))
    parser.add_argument('pos2', type=int, choices=list(range(4)))
    parser.add_argument('pos3', type=int, choices=list(range(2)))
    return parser

def main():
    parser = get_parser()
    print(parser.parse_args())

if __name__ == '__main__':
    main()

my completion commandline:

eval "$(shtab src.test.get_parser --prog=foo --shell=bash)"

If I do the regular

foo 6 4 <tab>

I get 0 1 choices as expected. But if I do

foo -- 6 4 <tab>

I get 0 1 2 3 completions

casperdcl commented 6 months ago

try now?

usidedown commented 6 months ago

try now?

Looks good! Even managed to complete a file starting with - (not possible without --)