Closed
Description
My snippet:
class Program
{
public class Args
{
[Option('n', "name", Required = true)]
public string Name { get; set; }
}
static void Main(string[] args)
{
Args parsedArgs;
Parser.Default.ParseArguments<Args>(args).WithParsed(result => parsedArgs = result).WithNotParsed(ThrowOnParseError);
}
private static void ThrowOnParseError(IEnumerable<Error> errors)
{
var excList = new List<Exception>();
foreach (var err in errors)
{
excList.Add(new ArgumentException(err.ToString()));
}
if (excList.Any())
throw new AggregateException(excList);
}
}
I would like to throw errors as ArgumentException with message being the same message that gets printed when error occurs. For example, when option -n is missing, this text is printed:
CmdLineParserTest 1.0.0.0
Copyright c 2019ERROR(S):
Required option 'n, name' is missing.-n, --name Required.
--help Display this help screen.
--version Display version information.
I would like to throw ArgumentException with "Required option 'n, name' is missing." being its message.
I looked into HelpText, but im not sure if it's what i need.