Skip to content

Instantly share code, notes, and snippets.

@Axemasta
Created May 14, 2018 16:12
Show Gist options
  • Save Axemasta/cd5a0f0f4e1809015ac66a13be607568 to your computer and use it in GitHub Desktop.
Save Axemasta/cd5a0f0f4e1809015ac66a13be607568 to your computer and use it in GitHub Desktop.
Command Line Parser Demo
class Options
{
// Omitting long name, defaults to name of property, ie "--verbose"
[Option(Default = false, HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }
}
class Program
{
static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args).WithParsed<Options>(o => {
if (o.Verbose)
{
Console.WriteLine($"Verbose output has been enabled. Current Arguments: -v {o.Verbose}");
Console.WriteLine("Quick Start Example! App is in Verbose mode so verbose messages will be shown!");
}
else
{
Console.WriteLine($"Current Arguments: -v {o.Verbose}");
Console.WriteLine("Quick Start Example!");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment