I have an option for a start date.
[Option('s', "startdate", Required = false, HelpText
and am using the -startdate 7/1/2020 as the arg
But no matter what I do, the args always end up being parsed as a shortname
"nddate 7/1/2020"
I would expect it to be 7/1/2020 and clean up that other stuff.
and am using the -startdate 7/1/2020 as the arg
But no matter what I do, the args always end up being parsed as a shortname
"nddate 7/1/2020"
It seems you use single dash. It should be, using double dash
--startdate 7/1/2020
Just for acceptable datetime format, check format of datetime based on CultureInfo.CurrentCulture , see also Multi Culture Support
I test in the same your Environment with OS: Linux Ubuntu 20.04 and datetime 7/1/2020 M/dd/yyyy is accepted as its format match CultureInfo.CurrentCulture datetime format.
Can you provide the property of start date? What is nddate?
nddate is just enddate being cut off. I'm assuming because i did -enddate, it assumed I was using -e as an option so it added the nddate as part of the string instead of the arg.
Here's a breakdown of what I see.
[Option('f', "folderId", Required = true, HelpText = "Required: The folder id to scan.")]
public string FolderId { get; set; }
Arg Input -f 123455
Expected Arg Result: 123455
Actual Arg Result is: 123455
Arg Input -folderId 123455
Expected Arg Result: 123455
Actual Arg Result is: olderId 123455
Arg Input --folderId 123455
Expected Arg Result: 123455
Actual Arg Result is: Option 'folderId 123455' is unknown. Required option f, folderId is missing
Do you pass commandline from Unix shell. Can you show:
Environment.Commandline
Environment.GetCommandLineArgs()
for 2nd, 3rd case.
For more reference, I am using the launch options json in VS Code
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ReportingTool.dll",
"args": ["--folderId 123455", "--startdate 10/12/19", "--enddate 7/1/2020"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
2nd case
.../ReportingTool.dll "-folderId 123455" "-startdate 10/12/19" "-enddate 7/1/2020"
.../bin/Debug/netcoreapp3.1/ReportingTool.dll
-folderId 123455
-startdate 10/12/19
-enddate 7/1/2020
3rd case
.../ReportingTool.dll "--folderId 123455" "--startdate 10/12/19" "--enddate 7/1/2020"
.../bin/Debug/netcoreapp3.1/ReportingTool.dll
--folderId 123455
--startdate 10/12/19
--enddate 7/1/2020
I find something interesting in the commandline args in launch.json which interpret the values in the Environment.GetCommandLineArgs()
"args": ["--folderId 123455", "--startdate 10/12/19", "--enddate 7/1/2020"]
That is invalid arguments because every option name and value are merged together, e.g, the argument "--folderId 123455" should be two arguments like: "--folderId" , "123455"
To correct the behaviour of the parser, modify args in launch.json as:
"args": ["--folderId", "123455", "--startdate", "10/12/19", "--enddate", "7/1/2020"]
Can you try and feedback if this resolved your issue?
2nd Case
the result was just olderId, the ID was skipped. But this is expected?
3rd Case
Works, I think you found the issue.
Thanks for feedback.
BTW, If you want to merge options(without space separator), it can be as:
ShortNames
if Short option is 'sand value12345'
Argument can be: -s12345
For LongNames
use = between option name and value, like:
--folderId=123455
Alternative argument can be:
"args": ["--folderId=123455", "--startdate=10/12/19", "--enddate=7/1/2020"]
Or
"args": ["-f123455", "-s10/12/19", "--enddate=7/1/2020"]
Most helpful comment
I find something interesting in the commandline args in
launch.jsonwhich interpret the values in the Environment.GetCommandLineArgs()That is invalid arguments because every option name and value are merged together, e.g, the argument
"--folderId 123455"should be two arguments like:"--folderId" , "123455"To correct the behaviour of the parser, modify args in
launch.jsonas:Can you try and feedback if this resolved your issue?