commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Display Options values for a verb.

Open sybaris opened this issue 2 years ago • 2 comments

Hi,

I have many verbs. I would like for each verbs to first display the option values automaticaly. Is there is a way to do that easily ?

Regards Sybaris

sybaris avatar Mar 13 '23 12:03 sybaris

I would like for each verbs to first display the option values automaticaly.

What do you mean? Can you give a descriptive example of what you want to have displayed? What should it look like exactly?

elgonzo avatar Mar 13 '23 12:03 elgonzo

Here an example with 2 verbs :


[Verb("Verb1", HelpText = "Verb1")]
internal class Verb1Options
{
    [Option(Required = true, HelpText = "Option1")]
    public string Option1 { get; set;}
    [Option(Required = true, HelpText = "Option2")]
    public string Option2 { get; set;}
}

[Verb("Verb2", HelpText = "Verb2")]
internal class Verb2Options
{
    [Option(Required = true, HelpText = "Option1")]
    public string OtherOption1 { get; set;}
    [Option(Required = true, HelpText = "Option2")]
    public string OtherOption2 { get; set;}
}

static void Main(string[] args)
{
  parser.ParseArguments<Verb1Options,Verb2Options>(args)
             .MapResult(
               (Verb1Options options) => RunVerb1(options),
               (Verb2Options options) => RunVerb2(options),
               errors => RunErrors(errors));
}


internal int RunVerb1(Verb1Options options)
{
    Console.WriteLine("Verb = Verb1");
    Console.WriteLine($"  Option1 = {options.Option1}");
    Console.WriteLine($"  Option2 = {options.Option2}");
    //.....
    // Then the code for treating the verb Verb1
}

internal int RunVerb2(Verb2Options options)
{
    Console.WriteLine("Verb = Verb2");
    Console.WriteLine($"  OtherOption1 = {options.OtherOption1}");
    Console.WriteLine($"  OtherOption2 = {options.OtherOption2}");
    //.....
    // Then the code for treating the verb Verb2
}

I search a way to automate the lines of code that in my example start with Console.WriteLine. The goal of these lines is to "log" the informations before proceeding to treatment of the verb...

sybaris avatar Mar 14 '23 22:03 sybaris