Please find the following snippet:
import argparse
parser = argparse.ArgumentParser(
description="Create plot from data",
formatter_class=lambda prog: argparse.HelpFormatter(
prog, max_help_position=27))
action = parser.add_mutually_exclusive_group(required=True)
action.add_argument('--foo', help="Create foo plot") # input is <filename>.foo
action.add_argument('--bar', help="Create bar plot") # Input is <filename>.bar
I run this in linux terminal emulator. Is it possible within python that, in the terminal, double tabiing will show only files with extension foo
or bar
, depending on argument, and not all the files in PWD
?
I have found TAB autocomplete python CLI, but that is a decade old. Is there any option now?
Update @Lenormju: I have updated the code as:
action.add_argument('--foo', help="Create foo plot", choices=('agr'))
action.add_argument(
'--bar', help="Create bar plot").completer = ChoicesCompleter('.agr')
So, now in terminal,
python ~/bin/code.py --foo [TAB][TAB]
I am expecting this to show files with .agr
extensions only. Instead it is still shown all the files present in PWD
.
Actually, this should not work, because "choices" means, I have to choose between 'a' 'g' or 'r'. May be I was not clear in the main question, show I have elaborated it.