I would like to know how to use python's argparse module to read arguments both from the command line and possibly from text files. I know of argparse's fromfile_prefix_chars
but that's not exactly what I want. I want the behavior, but I don't want the syntax. I want an interface that looks like this:
$ python myprogram.py --foo 1 -A somefile.txt --bar 2
When argparse sees -A, it should stop reading from sys.argv or whatever I give it, and call a function I write that will read somefile.text and return a list of arguments. When the file is exhausted it should resume parsing sys.argv or whatever. It's important that the processing of the arguments in the file happen in order (ie: -foo should be processed, then the arguments in the file, then -bar, so that the arguments in the file may override --foo, and --bar might override what's in the file).
Is such a thing possible? Can I write a custom function that pushes new arguments onto argparse's stack, or something to that effect?