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

bash: support -- delimeter #164

Merged
merged 1 commit into from
Mar 7, 2024
Merged

bash: support -- delimeter #164

merged 1 commit into from
Mar 7, 2024

Conversation

casperdcl
Copy link
Collaborator

@casperdcl casperdcl commented Feb 22, 2024

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@casperdcl
Copy link
Collaborator Author

/CC @usidedown does this work for you?

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

@usidedown
Copy link

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
Copy link
Collaborator Author

try now?

@usidedown
Copy link

try now?

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

@casperdcl casperdcl enabled auto-merge March 7, 2024 18:47
@casperdcl casperdcl merged commit 61ec99d into main Mar 7, 2024
9 checks passed
@casperdcl casperdcl deleted the double-dash branch March 7, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request external-request You asked, we did shell-bash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Complete only positional arguments after double dash ("--")
2 participants