Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

How to get Error message? #513

Copy link
Copy link
@IB38

Description

@IB38
Issue body actions

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 2019

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.