Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Options values for a verb. #879

Open
sybaris opened this issue Mar 13, 2023 · 2 comments
Open

Display Options values for a verb. #879

sybaris opened this issue Mar 13, 2023 · 2 comments

Comments

@sybaris
Copy link

sybaris commented Mar 13, 2023

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

@elgonzo
Copy link

elgonzo commented Mar 13, 2023

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?

@sybaris
Copy link
Author

sybaris commented Mar 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants