[C#]Command Line Parser Library
[OptionArray("o", "output", HelpText = "The output files to generate.")]
public string[] OutputFiles { get; set; }
[OptionList("k", "keywords", Separator = ':', HelpText = "Specify keywords to search the text, separated by a colon.")]
public List<string> Keywords { get; set; }
[ValueList(typeof(List<string>), MaximumElements = 3)]
public List<string> Items { get; set; }
...
}</pre></div>
[HelpOption]
public string GetUsage()
{
...
}
}</pre></div>
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("CommandLine parser library demo...");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(string.Format("Usage: {0} [options]", Path.GetFileName(Application.ExecutablePath)));
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("options:");
help.AddOptions(this);
return help;
}</pre></div>
[HelpOption]
public string GetUsage()
{
var help = new HelpText
{
Heading = new HeadingInfo(Application.ProductName, Application.ProductVersion),
Copyright = GetAssemblyCopyright(),
AdditionalNewLineAfterOption = true,
AddDashesToOption = true
};
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("CommandLine parser library demo...");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(string.Format("Usage: {0} [options]", Path.GetFileName(Application.ExecutablePath)));
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("options:");
help.AddOptions(this);
return help;
}</pre></div>
public class Options
{
[Option("i", "input", Required = true, HelpText = "Input file to read.")]
public string InputFile { get; set; }
[OptionArray("o", "output", HelpText = "The output files to generate.")]
public string[] OutputFiles { get; set; }
[OptionList("k", "keywords", Separator = ':', HelpText = "Specify keywords to search the text, separated by a colon.")]
public List<string> Keywords { get; set; }
[ValueList(typeof(List<string>), MaximumElements = 3)]
public List<string> Items { get; set; }
private string GetAssemblyCopyright()
{
var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
return "";
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
[HelpOption]
public string GetUsage()
{
var help = new HelpText
{
Heading = new HeadingInfo(Application.ProductName, Application.ProductVersion),
Copyright = GetAssemblyCopyright(),
AdditionalNewLineAfterOption = true,
AddDashesToOption = true
};
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("CommandLine parser library demo...");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(string.Format("Usage: {0} [options]", Path.GetFileName(Application.ExecutablePath)));
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("options:");
help.AddOptions(this);
return help;
}
}
}
}