argparse icon indicating copy to clipboard operation
argparse copied to clipboard

expect File arg to take standard input / output stream as a value

Open xnslong opened this issue 2 years ago • 2 comments

When I define a File arg (like following) to specify an input file,

-i <input-file>

I wish we can specify the - value to input from the standard input stream. However, it will report error now.

if it's defined with a String arg, the help message will display like -i "<value>"(cannot tell this should be a file), not as expected very much.

It is the same case for the output file. I wish to specify the - value to output to standard output stream.

xnslong avatar Mar 18 '22 09:03 xnslong

You can provide Options.Help and write there that it must be a file, in addition you can add validation to the argument that will check whether string is a file or if it is "-".

I can see how it could be useful, but then would also need to account for ability to pipe stdin etc, which is better handled from application code than from this library.

I've added File early on, but it is rather complex to deal with and there are many edge cases where it can fail. It currently only exists for backward compatibility and I myself stopped using this argument type and just use String instead.

akamensky avatar Apr 20 '22 07:04 akamensky

I think it can be done with minimal change, PR is welcome.

akamensky avatar Apr 20 '22 07:04 akamensky