commandline
commandline copied to clipboard
Display Options values for a verb.
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
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?
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...