Exemple #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);
        }
Exemple #2
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);
        }
Exemple #3
0
        public static void Usage(PickMethod method = PickMethod.None)
        {
            StringBuilder sb   = new StringBuilder();
            string        name = nameof(ImageOpenCV);

            sb
            .WL()
            .WL(0, $"Usage {name} (method) [options]")
            .WL(0, "Options:")
            .WL(1, "-h / --help", "Show full help")
            .WL(1, "(method) -h", "Method specific help")
            .WL(1, "--methods", "List possible methods")
            ;

            if (ShowFullHelp)
            {
                foreach (PickMethod a in Aids.EnumAll <PickMethod>())
                {
                    IMain func = Registry.Map(a);
                    func?.Usage(sb);
                }
            }
            else if (method != PickMethod.None)
            {
                IMain func = Registry.Map(method);
                func?.Usage(sb);
            }
            else
            {
                if (ShowHelpMethods)
                {
                    sb
                    .WL()
                    .WL(0, "Methods:")
                    .PrintEnum <PickMethod>(1)
                    ;
                }
            }

            Log.Message(sb.ToString());
        }
Exemple #4
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);
        }