Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created April 2, 2014 21:52
Show Gist options
  • Select an option

  • Save danidiaz/9943986 to your computer and use it in GitHub Desktop.

Select an option

Save danidiaz/9943986 to your computer and use it in GitHub Desktop.
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