akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
604 stars 62 forks source link

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

Open xnslong opened 2 years ago

xnslong commented 2 years ago

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.

akamensky commented 2 years ago

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 commented 2 years ago

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