Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public Opt(OptDef optDef)
 {
     this.Option = optDef;
     this.Value  = optDef.Default;
 }