public void FallToDefaultHookWithEmptyArgs() { var defaultHookPopulated = false; var options = new CommandDef(() => defaultHookPopulated = true) { {'h', "Print help message", () => { }} }; var extraArgs = options.Parse(new string[] {}); Assert.Empty(extraArgs); Assert.True(defaultHookPopulated); }
static void Main(string[] args) { var options = new CommandDef(ShortHelp) { {'h', "help", "print this message", ShortHelp}, {"server", "server address", (string v) => _server = v}, {'u', "user", "user name", (string v) => _username = v}, {"help", "print detailed help message", new CommandDef(HelpUsage) { {"commands", "list all subcommands", new CommandDef(ListSubCommands)}, {"options", "description of all global options", new CommandDef(ListOptions)}, }}, {"checkout", "Checkout files", new CommandDef(Checkout) { {'f', "force", "force checkout", () => _forceCheckout = true} }}, {"checkin", "Checkin files", new CommandDef(Checkin) { {'a', "all", "checkin all files", () => _checkinAll = true} }} }; _extra = options.Parse(args); _extra.ForEach(Console.Out.WriteLine); Console.Out.WriteLine(_server); Console.Out.WriteLine(_username); }