static void HandleOpt(ParsedOpts results, string arg, OptDef opt, string value) { if (opt != null) { Opt optVal = results.Opts[opt.Long]; if (value != null) { if (!opt.Value) { results.Error = String.Format("Argument '{0}' doesn't take a value", arg); } else if (optVal.Count > 0) { results.Error = String.Format("Multiple values found for '{0}'", arg); } else { optVal.Value = value; } } else if (opt.Value) { results.Error = String.Format("Argument '{0}' requires a value", arg); } optVal.Count++; } else { results.Error = String.Format("Unrecognized argument: '{0}'", arg); } }
public ProgramOpts AddOption(string longName, string help, Func <OptDef, OptDef> func = null) { var opt = new OptDef(longName, help); if (func != null) { opt = func(opt); } Options.Add(opt); return(this); }
public Opt(OptDef optDef) { this.Option = optDef; this.Value = optDef.Default; }