Open njcuk9999 opened 1 month ago
And to add a dymanic argument choice:
import argparse
import argcomplete
import os
def directory_completer(prefix, parsed_args, **kwargs):
# Return a list of directories in the current directory
return [d for d in os.listdir('.') if os.path.isdir(d) and d.startswith(prefix)]
def main():
parser = argparse.ArgumentParser(description="Example script with dynamic tab completion")
# Add an argument that uses the directory completer
parser.add_argument('--dir', help='Directory argument').completer = directory_completer
# Integrate argcomplete
argcomplete.autocomplete(parser)
args = parser.parse_args()
print(f"Directory: {args.dir}")
There is a module that can make arguments autocomplete
However you need to do some stuff outside python:
We have to install argcomplete + activate it on a machine (Question: How do we do this inside the pip setup stuff?)
This goes inside every code that has arguments