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

Improve CLI Argument Parsing to Handle Space Separated Values #581

Closed
wants to merge 1 commit into from

Conversation

Alstruit
Copy link

@Alstruit Alstruit commented Dec 27, 2024

The original implementation assumed each argument would contain at most one value, which could cause exceptions when attempting to parse multiple values (e.g., -depot "11 12 13") into numeric types.

  • The code also checks if the TypeConverter for the given type T is available and logs a warning if it’s not, preventing potential null-reference issues.

  • It stops parsing values once it encounters a new parameter which is consistent with typical CLI usage patterns.

System.ArgumentException occurs when handling space-separated arguments provided as a single string. GetParameterList<T>() function attempts to parse the string of numbers as a UInt32.
var strParam = args[index];

// Handle the scenario where we have a single space-separated string of values
if (strParam.Contains(" ") && !strParam.StartsWith("-"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If args is already split by space, how would this ever hit?

@xPaw
Copy link
Member

xPaw commented Dec 29, 2024

To be honest I would prefer #234 rather than trying to hack in support for this in the current system, but System.CommandLine was kind of abandoned...

I've had success using https://github.com/Cysharp/ConsoleAppFramework

@Alstruit
Copy link
Author

I agree that this appears to be hacky. To be fair this only happens if one of the arguments is enclosed with quotes.
I'll close this one and try to use the one you mentioned. Thanks.

@Alstruit Alstruit closed this Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants