4

I have a python script that takes in several files as required arguments, which I parse with argparse.

parser = argparse.ArgumentParser()
parser.add_argument("-i", "--imgtfile", required=True, help="IMGT file")
parser.add_argument("-s", "--fastqfile", required=True, help="FASTQ file")
parser.add_argument("-g", "--gene", required=True, help="Gene to extract")
parser.add_argument("-o", "--outfile", help="name of the output file")
# ... more arguments
argcomplete.autocomplete(parser) # <-- this doesn't help
args = parser.parse_args()

The issue is that the files have pretty long and annoying names. Shell tab expansion works great if the arguments are positional (i.e. no flags) but if I have flags the tab expansion doesn't work anymore. On the other hand I'd like to keep the flags to not hardcode the order of arguments.

I have looked into argcomplete but can't really get it to work the way I like. It seems like I either need the choices option in add_argument, and/or fiddle with bash to enable global completion.

Since I am working remotely on a server, I'm a bit conservative about this. Seems to me as if there should be a simpler way. Any suggestions?

posdef
  • 6,498
  • 11
  • 46
  • 94
  • 1
    Related: [Python argparse and bash completion](http://stackoverflow.com/questions/8387924/python-argparse-and-bash-completion) – Chris_Rands Dec 05 '16 at 12:38
  • @Chris_Rands Thanks. It's related yes, but doesn't provide a useful answer, as far as I can tell – posdef Dec 05 '16 at 12:49
  • Perhaps you should clarify why `argcomplete` does not work for you – Chris_Rands Dec 05 '16 at 12:59
  • @Chris_Rands the way it requires me to fiddle with system settings. I am generally not too keen on randomly running scripts that I have not written, on a server I am responsible for – posdef Dec 06 '16 at 09:17

0 Answers0