CommandLineParser

Seham 1 Reputation point
2021-03-31T09:06:05.89+00:00

Hi,
I am using CommandLineParser C# library to parse in new commands to my application, I wonder if there is a way to show or print out the errors from not passing one command not as a general error. I mean in case if one command is missing how to show exactly the missing command error.

Thanks in advance.

Here is my code snippet

var result = Parser.Default.ParseArguments<CommandLineOptions>(args)
               .MapResult(async (CommandLineOptions opts) =>
               {
                   cmd = opts;
                   return 0;
               },
           errs => Task.FromResult(-1)
           );
            if (result.Result == -1)
            {
                Console.WriteLine("Error in parsing line commands"); // is there a way to tell them what was wrong i.e. which particular
                                                                     // /argument was bad

            }
            else
            {
                if (cmd.Validate())
                {
                    RunAsync().GetAwaiter().GetResult();
                }
            }

        }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,141 questions
0 comments No comments
{count} votes