clagraff / argparse

A Golang argument parser for command line arguments.
MIT License
24 stars 4 forks source link

Support file-stored parser arguments? #36

Open clagraff opened 7 years ago

clagraff commented 7 years ago

Derived from: https://docs.python.org/dev/library/argparse.html#fromfile-prefix-chars

Do we want to allow for using a certain prefix-character(s) to indicate that a file being specified needs to be read, and have each line added as individual arguments to the parser, in place of the original argument.

Here is the python example:

>>> with open('args.txt', 'w') as fp:
...     fp.write('-f\nbar')
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
>>> parser.add_argument('-f')
>>> parser.parse_args(['-f', 'foo', '@args.txt'])
Namespace(f='bar')

So, the library could do something similar:

parser.FromFilePrefix("@")

Which would expand the file, line by line, to individual arguments. Is this worth implementing? I have never heard of anyone using this in practice.

clagraff commented 7 years ago

Also of note: https://docs.python.org/dev/library/argparse.html#type Should probobly support a "file" option value type.

clagraff commented 7 years ago

Changing to a question.