I’m trying to use the argparse python module for a project, the code looks like this
import argparse
def main():
p = argparse.ArgumentParser()
mode = p.add_mutually_exclusive_group(required=True)
mode.add_argument("-f", "--file", type=str)
mode.add_argument("-d", "--directory", type=str)
p.add_argument("-o", "--output",
default="stdout",
type=str,
required=False)
args = p.parse_args()
if __name__ == "__main__":
main()
Here’s the problem
When I try to run it like this
python script.py path/to/my
And then press tab, it gives me a list of BOTH directories and files, that’s all fine
HOWEVER, if I do it like this
python script.py -f path/to/my
And then press tab, it just completes it already and throws a directory in there, if there are more directories, then it just gives me a list of directories, it completely ignores the files, which is quite frustrating…
I have no idea where the problem is…
Any ideas?