Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

back slash at end of string option doesnt work #44

Closed
EricZimmerman opened this issue Jul 17, 2015 · 3 comments
Closed

back slash at end of string option doesnt work #44

EricZimmerman opened this issue Jul 17, 2015 · 3 comments

Comments

@EricZimmerman
Copy link

if i have this:

p.Setup(arg => arg.Directory)
.As("Dir")
.WithDescription("\tDirectory to look for hives (recursively). --Hive or --Dir is required.");

and then call the program like this:

foo.exe --dir "C:\temp\bar" --sk [veris

things work, but if i do this

foo.exe --dir "C:\temp\bar" --sk [veris

i get this error

Option '--dir' parse error: could not parse 'C:\temp\bar" --sk [veris' to 'System.String'.

seems that last back slash is causing issues. any work around?

@siywilliams
Copy link
Member

The array passed into static void Main(string[] args) by the .Net framework seems to be different depending on whether you have the final '' character in it.

This article also explains the problem.

Fclp is expecting the .Net framework to have already parsed --dir "C:\temp\bar" --sk [veris into an array with 4 strings. This doesn't happen as the backslash seems to have escaped some parsing condition which has resulted in 2 strings. As a result it thinks the string "C:\temp\bar" --sk [veris is the value for the --dir option, which fails to parse because of the whitespace (it thinks the whitespace is seperating another value which is only valid if you're parsing into a List)

--dir "C:\temp\bar" --sk [veris

2015-07-17 18_30_14-fluentcommandlineparser debugging - microsoft visual studio

--dir "C:\temp\bar" --sk [veris

2015-07-17 18_29_19-fluentcommandlineparser debugging - microsoft visual studio

@nelyom
Copy link

nelyom commented Aug 16, 2015

I've ended up resolving this via my own parser pulling from Environment.CommandLine, rather than rely on the incoming string[] args.

The funny rules on the .NET (and underneath that CommandLineToArgvW) are easily worked around if a little bit of logic is applied.

I've submitted my little project here. https://github.com/nelyom/cmdLineTokenizer

@NTTAKR
Copy link

NTTAKR commented Apr 25, 2016

See also Issue #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants