It seems to me that your best option is to preprocess sys.argv
inserting a special token which you check for instead of -
.
args = [ '<stdin>:'+x[2:] if x.startswith('-:') else x for x in sys.argv[1:] ]
opt_struct = parser.parse_args(args)
In this case, you would parse <stdin>
as standard input in your program instead of -
.
The transform gets a little more complicated if the :
and the stuff after it are optional, but this is the gist of it anyway.
9 times out of 10, these problems are likely impossible to solve with optparse
, really tricky/messy to solve with argparse
and trivial to solve by preprocessing sys.argv
-- But maybe that's just my experience ...