示例#1
0
        //find or default a parameter with two arguments
        public Result Default <T, U>(string @switch, out T tval, out U uval,
                                     T tdef = default(T), U udef = default(U))
            where T : IConvertible where U : IConvertible
        {
            tval = tdef;
            uval = udef;
            int i = Args.IndexOf(@switch);

            if (i == -1)
            {
                return(Result.Missing);
            }
            if (i + 2 >= Args.Count)
            {
                Tell.MissingArgument(@switch);
                return(Result.Invalid);
            }
            if (!Aids.TryParse(Args[i + 1], out tval))
            {
                Tell.CouldNotParse(@switch, Args[i + 1]);
                return(Result.Invalid);
            }
            if (!Aids.TryParse(Args[i + 2], out uval))
            {
                Tell.CouldNotParse(@switch, Args[i + 2]);
                return(Result.Invalid);
            }
            Args.RemoveAt(i + 2);
            Args.RemoveAt(i + 1);
            Args.RemoveAt(i);
            return(Result.Good);
        }
示例#2
0
 public Result Expect(out string val, string name)
 {
     if (Result.Good != Has(out val) || String.IsNullOrWhiteSpace(val))
     {
         Tell.MustProvideInput(name);
         return(Result.Invalid);
     }
     return(Result.Good);
 }
示例#3
0
        public static bool Parse(string[] args, out string[] prunedArgs)
        {
            prunedArgs = null;
            var pArgs = new List <string>();

            int len = args.Length;

            for (int a = 0; a < len; a++)
            {
                string curr = args[a];
                if (curr == "-h" || curr == "--help")
                {
                    if (Method == PickMethod.None)
                    {
                        ShowFullHelp = true;
                    }
                    else
                    {
                        ShowHelpMethods = true;
                    }
                }
                else if (curr == "--methods")
                {
                    ShowHelpMethods = true;
                }
                else if (Method == PickMethod.None)
                {
                    PickMethod which;
                    if (!Aids.TryParse <PickMethod>(curr, out which))
                    {
                        Tell.UnknownMethod(curr);
                        return(false);
                    }
                    Method = which;
                }
                else
                {
                    pArgs.Add(curr);
                }
            }

            if (ShowFullHelp || ShowHelpMethods)
            {
                Usage(Method);
                return(false);
            }

            if (Method == PickMethod.None)
            {
                Tell.MethodNotSpecified();
                return(false);
            }

            prunedArgs = pArgs.ToArray();
            return(true);
        }
示例#4
0
        public Result Expect <T>(string @switch, out T val) where T : IConvertible
        {
            var has = Default(@switch, out val);

            if (Result.Good != has)
            {
                if (has == Result.Missing)
                {
                    Tell.MustProvideInput(@switch);
                }
                return(Result.Invalid);
            }
            return(Result.Good);
        }
示例#5
0
        public Result Expect(string @switch)
        {
            var has = Has(@switch);

            if (Result.Good != has)
            {
                if (has == Result.Missing)
                {
                    Tell.MustProvideInput(@switch);
                }
                return(Result.Invalid);
            }
            return(Result.Good);
        }
示例#6
0
        //find or default a parameter with one argument
        public Result Default <T>(string @switch, out T val, T def = default(T)) where T : IConvertible
        {
            val = def;
            int i = Args.IndexOf(@switch);

            if (i == -1)
            {
                return(Result.Missing);
            }
            if (i + 1 >= Args.Count)
            {
                Tell.MissingArgument(@switch);
                return(Result.Invalid);
            }
            if (!Aids.TryParse(Args[i + 1], out val))
            {
                Tell.CouldNotParse(@switch, Args[i + 1]);
                return(Result.Invalid);
            }
            Args.RemoveAt(i + 1);
            Args.RemoveAt(i);
            return(Result.Good);
        }