zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

Support reading arguments from a file #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Feature request:

It would be nice if argparse supported a way to allow users to specify 
additional command line arguments in a file.  E.g.:

  myscript -p foo @argsfile -f bar

where there's a file named "argsfile" in the current working directory 
which contains additional command line arguments.

I've attached a patch that implements this.  It adds an additional keyword 
argument to the ArgumentParser class, named "fromfile_prefix_chars" that 
specifies characters that prefix the name of a file to read additional 
arguments from.  By default this is None, which means never read arguments 
from a file, but if you were to set it to '@', then the above example would 
work.

I've added a test and modified the docs.  I've also verified that the tests 
pass on Linux and Windows, with Python 2.4, 2.5, and 2.6.  Thanks for 
considering this.

Original issue reported on code.google.com by zhir...@gmail.com on 11 Jul 2009 at 4:58

Attachments:

GoogleCodeExporter commented 9 years ago
My first thought on this was "why the funny @ character?" but I looked around, 
and
this does seem to be supported by a number of command line tools.

So I've added a variant of your patch in r24. Please try it out and let me know 
if it
doesn't work for you. Thanks for the patch!

Original comment by steven.b...@gmail.com on 12 Jul 2009 at 10:21

GoogleCodeExporter commented 9 years ago
Thanks!  It seems to be working great for me.

Original comment by zhir...@gmail.com on 12 Jul 2009 at 11:41