Tyrrrz/CliFx

Order changes parser behavior?

sommmen opened this issue · 5 comments

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"] 

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.

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!

No problem.

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...

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