Open gt2847c opened 7 years ago
Just thought I'd mention that I did try the DirectoryArgument decorator, but got the same results when the -d argument is first.
Thanks for the interesting post, maybe we could add some alternative parsing using Environment.CommandLine in the future.
I ran into this problem with the .NET args parsing, so this isn't a problem in CommandLineParser, but I thought I'd mention as it can make using your package challenging where there are arguments that have quoted paths. When passing a path having spaces as an argument, you have to double quote the path to make sure it's consumed as a single argument. The problem is that when the path has a trailing backslash followed by the closing double quote, the .NET parser treats it as an escaped double quote and any trailing options following get munged into that argument. I am able to work around it by looking for a double quote in the argument and replacing it with a backslash so long as it's the last argument on the command line. MSDN's remarks on command line processing notes the behavior which is how it acts, even if it happens to cause difficulties working with quoted paths:
Here's a couple of examples,
With path statement last:
It sees both arguments, but the path contains a double quote rather than the trailing backslash. This can be worked around by replacing the escaped quote, but it requires the path always be in last position as an argument.
With path statement first:
This triggers an exception because the -f argument is required:
In this case, the -f and filename are consumed by the -d. Again, this is a problem with the .NET parsing of the command line, here's the args variable from the second argument: `
args {string[2]} string[] [0] "-d" string [1] "c:\program files\" -f output.csv" string
`
Not sure if there's a good workaround that can be done in your package given you might actually want the escaped quotes in some cases (maybe a decorator denoting a path). I know that this particular argument is intended to be path, so I can make allowances for it, but it does make it more difficult as I have to require the user to order the arguments such that the path is last which allows me to use your package (much easier for me) or I have to directly work with the Environment.CommandLine to pick out the bits I need and essentially build my own parser specifically to handle this..