question

Seham-8903 avatar image
0 Votes"
Seham-8903 asked

CommandLineParser

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();
                 }
             }
    
         }


dotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers