Exemple #1
0
        static private ArgOptions parse_options(string[] args)
        {
            ArgOptions opts = new ArgOptions(false);

            var p = new OptionSet()
            {
                { "e|event=", "Set the event content.\n",
                  v => opts.evt = v },
                { "t|type=", "Set the type content.\n",
                  v => opts.typ = v },
                { "n|name=", "set the name to be performed\n",
                  v => opts.name = v },
                { "o|op=", "Set the action operation\n",
                  v => opts.op = v },
                { "v|value", "Set action",
                  v => opts.value = v },
                { "verbose", "increase debug message verbosity",
                  v => { if (v != null)
                         {
                             ++opts.verbosity;
                         }
                  } },
                { "h|help", "show this message and exit",
                  v => { opts.showHelp = true; } },
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);  //return un handled args
                if (extra.Count > 0)
                {
                    Console.WriteLine("Unhandled args: " + String.Join(" ", extra));
                }
            }
            catch (OptionException e)
            {
                Console.Write("greet: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `greet --help' for more information.");
            }

            if (opts.showHelp)
            {
                ShowHelp(p);
            }

            return(opts);
        }
Exemple #2
0
        /*
         * static void Debug(string format, params object[] args)
         * {
         *  if (verbosity > 0)
         *  {
         *      Console.Write("# ");
         *      Console.WriteLine(format, args);
         *  }
         * }*/

        static void Main(string[] args)
        {
            // args = "-t form -o list".Split();
            // args = "-n button_open -o click".Split();
            // args = "-t result -o data".Split();

            ArgOptions opts = parse_options(args);

            if (!String.IsNullOrEmpty(opts.op))
            {
                Controller ctl = new Controller(opts);
                ctl.PipeStart();
                ctl.PipeStop();
            }
        }
Exemple #3
0
        private string ArgsToPipeCmd(Dictionary <string, string> formTable, ArgOptions cmdOpts)
        {
            List <string>        raw        = new List <string>();
            FirstCharToUpperOnly UpperFirst = input =>
            {
                if (String.IsNullOrEmpty(input))
                {
                    throw new ArgumentException("ARGH!");
                }
                return(input.First().ToString().ToUpper() + input.Substring(1).ToLower());
            };


            if (!String.IsNullOrEmpty(cmdOpts.evt))
            {
                raw.Add(UpperFirst(cmdOpts.evt));
            }
            else
            {
                raw.Add("Event");
            }

            if (!String.IsNullOrEmpty(cmdOpts.typ))
            {
                raw.Add(UpperFirst(cmdOpts.typ));
            }

            if (!String.IsNullOrEmpty(cmdOpts.name))
            {
                if (formTable.ContainsKey(cmdOpts.name))
                {
                    string type = formTable[cmdOpts.name];
                    if (String.IsNullOrEmpty(cmdOpts.typ))
                    {
                        raw.Add(type);
                    }
                    raw.Add(cmdOpts.name);
                }
            }

            if (!String.IsNullOrEmpty(cmdOpts.op))
            {
                raw.Add(UpperFirst(cmdOpts.op));
            }

            return(String.Join(" ", raw.ToArray()));
        }
Exemple #4
0
        //private List<string> cmds;

        public Controller(ArgOptions opts)
        {
            this.cmdOpts = opts;
            _pipeStatus  = "";
        }