Created
April 2, 2014 21:52
-
-
Save danidiaz/9943986 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using Npgsql; | |
| using CommandLine; | |
| using CommandLine.Text; | |
| // http://commandline.codeplex.com/ | |
| namespace Project1 | |
| { | |
| // Define a class to receive parsed values | |
| class Options | |
| { | |
| [Option('r', "read", Required = true, | |
| HelpText = "Input file to be processed.")] | |
| public string InputFile { get; set; } | |
| [Option('v', "verbose", DefaultValue = true, | |
| HelpText = "Prints all messages to standard output.")] | |
| public bool Verbose { get; set; } | |
| [ParserState] | |
| public IParserState LastParserState { get; set; } | |
| [HelpOption] | |
| public string GetUsage() | |
| { | |
| return HelpText.AutoBuild(this, | |
| (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current)); | |
| } | |
| } | |
| class Class1 | |
| { | |
| static void Main(string[] args) | |
| { | |
| var options = new Options(); | |
| if (CommandLine.Parser.Default.ParseArguments(args, options)) | |
| { | |
| // Values are available here | |
| if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile); | |
| } | |
| Console.WriteLine("aa bb cc"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment