You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, thanks a lot for the great starting point on building my own very simple command line arg helper.
One very simple thing I added was an last parsing step, to remove options passed without an name (only - or --).
I changed the method to return an info about the parsing process: public static IReadOnlyList<CommandLineOption> ParseOptions(string[] arguments, out string info) { ...
And as a very last step, I added:
// Clean up invalid options (e.g. - or -- without name)
int invalidOptions = results.RemoveAll(option => string.IsNullOrEmpty(option.Name));
info = $"Parsed <{results.Count}> valid and <{invalidOptions}> invalid command line args";
return results;
The text was updated successfully, but these errors were encountered:
Thanks for the feedback. Great, that it's useful. 👍 Probably one could also add some options like passing a ParserOptions.Strict, so it either fails with an Exception for an empty option name or just ignores empty arguments. You could also think about returning a Parse Result instead of an out Parameter like:
public class ParseResult
{
public string[] Arguments { get; set; }
public IReadOnlyList<CommandLineOption> Result { get; set; }
public int[] ValidArguments { get; set; }
public int[] InvalidArguments { get; set; }
}
Where ValidArguments and InvalidArguments could be the indices, that are problematic.
First, thanks a lot for the great starting point on building my own very simple command line arg helper.
One very simple thing I added was an last parsing step, to remove options passed without an name (only - or --).
I changed the method to return an info about the parsing process:
public static IReadOnlyList<CommandLineOption> ParseOptions(string[] arguments, out string info) { ...
And as a very last step, I added:
The text was updated successfully, but these errors were encountered: