Created
May 14, 2018 16:12
-
-
Save Axemasta/cd5a0f0f4e1809015ac66a13be607568 to your computer and use it in GitHub Desktop.
Command Line Parser Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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