Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.48k stars 60 forks source link

Order changes parser behavior? #45

Closed sommmen closed 4 years ago

sommmen commented 4 years ago

For some reason the first sample below works, but the second does not. For some reason the ordening of the options change the behaviour of the parser (or i'm missing something).

1>  "C:\Repos\HMI4\Tools\HmiPluginDllManager\bin\Debug\netcoreapp3.1\HmiPluginDllManager.exe" [preview] CpyPluginDlls -p "WebHmi.HmiPlugins" -c "Debug" -o "C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug\"
Parser preview:
CpyPluginDlls [-p WebHmi.HmiPlugins] [-c Debug] [-o C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug"] 
"C:\Repos\HMI4\Tools\HmiPluginDllManager\bin\Debug\netcoreapp3.1\HmiPluginDllManager.exe" [preview] CpyPluginDlls -p "WebHmi.HmiPlugins" -o "C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug\" -c "Debug"
Parser preview:
CpyPluginDlls [-p WebHmi.HmiPlugins] [-o 
 C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug" -c Debug"] 
Tyrrrz commented 4 years ago

Looks like the last quote is actually escaped because you put \" in the file path which escapes the quote. If you drop the slash, it parses it correctly:

test.exe [preview] CpyPluginDlls -p "WebHmi.HmiPlugins" -o "C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug" -c "Debug"

Parser preview:
<CpyPluginDlls> [-p WebHmi.HmiPlugins] [-o C:\Repos\HMI4\Machines\Kytl320\HmiUiKytl320\bin\Debug] [-c Debug]

Note that the handling and escaping of quotes is actually not done by CliFx but by .NET itself.

sommmen commented 4 years ago

Looks like the last quote is actually escaped because you put \" in the file path which escapes the quote.

You're right - I was looking like a madman for this issue. Much obliged!

Tyrrrz commented 4 years ago

No problem.

sommmen commented 4 years ago

I am calling this script via MSBuild, so "$(ProjectDir)$(OutDir)" got expanded to the path with the / at the end, then ofcourse came the quote so when that was passed to cmd.exe it escaped it...

Tyrrrz commented 4 years ago

One thing you can do is replace the backslashes with forward slashes, those are also supported in paths and don't cause issues.