-
Notifications
You must be signed in to change notification settings - Fork 85
So, how does FCLP compare to other parsers?
Here is a basic side-by-side syntax comparison between the Fluent Command Line Parser and other popular command line parsers. The examples are taken from their main pages, with the right column containing the code converted to the FCLP syntax.
NDesk.Options | Fluent Command Line Parser |
---|---|
```c#
static void Main(string[] args)
{
string data = null;
bool help = false;
int verbose = 0;
var p = new OptionSet () { { "file=", v => data = v }, { "v|verbose", v => { ++verbose; } }, { "h|?|help", v => help = v != null }, }; List extra = p.Parse (args); }
|
|
Command Line Parser | Fluent Command Line Builder |
```c#
// 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 filename to console.")] public bool Verbose { get; set; } [ParserState] public IParserState LastParserState { get; set; } [HelpOption] public string GetUsage() { return HelpText.AutoBuild(this, hlp => HelpText.DefaultParsingErrorsHandler(this, hlp)); } } // Consume them static void Main(string[] args) { var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { // Values are available here if (options.Verbose) Console.WriteLine("File: {0}", options.InputFile); } }
|