You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all, I am trying to use shtab for the first time. I would like to autocomplete a positional argument from a
list. I made a choice function titleselector that selects from a list based on a prefix. This does not work for me, but
I suspect that there is an error in how I try to use shtab. I suspect that this use case is a common one? I could not find any code examples for this.
Help appreciated!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import shtab # for completion magic
tptitles = """\
TP01_Calculating_checksums_using_seguid_calculator
TP02_Visualizing_linear_and_circular_DNA_with_ApE
TP03_In-silico_sub_cloning_using_ApE
""".splitlines()
def titleselector(prefix):
return [title for title in tptitles if title.startswith(prefix)]
parser = argparse.ArgumentParser(description='Correct TPs')
shtab.add_argument_to(parser, ["-s", "--print-completion"]) # magic!
parser.add_argument('title',
choices=tptitles,
help='tp to correct.').complete = titleselector
parser.add_argument('--student',
dest='studentinfo',
action='store',
help='a string thad identifies the student.')
args = parser.parse_args()
The text was updated successfully, but these errors were encountered:
BjornFJohansson
changed the title
Selecting from a predefined list
[Question] Selecting from a predefined list
Mar 7, 2024
Hi all, I am trying to use shtab for the first time. I would like to autocomplete a positional argument from a
list. I made a choice function
titleselector
that selects from a list based on a prefix. This does not work for me, butI suspect that there is an error in how I try to use shtab. I suspect that this use case is a common one? I could not find any code examples for this.
Help appreciated!
The text was updated successfully, but these errors were encountered: