Пример #1
0
        /// <summary>
        /// Method to check the passed arguments
        /// </summary>
        /// <param name="tuple">Argument tuple as reference</param>
        /// <param name="argValue">Passed argument value</param>
        /// <param name="argType">The expected type of the argument</param>
        /// <returns>The expected type of the next argument. In case of -r|--run and -l|--log, this is configFile or logFile</returns>
        private static ArgsTuple.ArgType CheckArgs(ref ArgsTuple tuple, string argValue, ArgsTuple.ArgType argType)
        {
            string arg = argValue;

            ArgsTuple.ArgType nextArgIs = ArgsTuple.ArgType.flag;
            if (argType == ArgsTuple.ArgType.flag)
            {
                arg = arg.ToLower();
                if (arg == "--run" || arg == "-r")
                {
                    tuple.Run = true;
                    nextArgIs = ArgsTuple.ArgType.configFile;
                }
                else if (arg == "--help" || arg == "-h")
                {
                    tuple.Help = true;
                    nextArgIs  = ArgsTuple.ArgType.flag;
                }
                else if (arg == "--output" || arg == "-o")
                {
                    tuple.Output = true;
                    nextArgIs    = ArgsTuple.ArgType.flag;
                }
                else if (arg == "--stop" || arg == "-s")
                {
                    tuple.HaltOnError = true;
                    nextArgIs         = ArgsTuple.ArgType.flag;
                }
                else if (arg == "--log" || arg == "-l")
                {
                    tuple.Log = true;
                    nextArgIs = ArgsTuple.ArgType.logFile;
                }
                else if (arg == "--example" || arg == "-e")
                {
                    tuple.Demo = true;
                    nextArgIs  = ArgsTuple.ArgType.flag;
                }
                else if (arg == "--docs" || arg == "-d")
                {
                    tuple.Docs = true;
                    nextArgIs  = ArgsTuple.ArgType.flag;
                }
                else if (arg == "--markdown" || arg == "-m")
                {
                    tuple.Markdown = true;
                    nextArgIs      = ArgsTuple.ArgType.flag;
                }
                else
                {
                    if (arg.StartsWith("--param") || arg.StartsWith("-p"))
                    {
                        Parameter p = Parameter.Parse(argValue);
                        Parameter.AddParameter(p, true);
                        nextArgIs = ArgsTuple.ArgType.flag;
                    }
                    else
                    {
                        nextArgIs = ArgsTuple.ArgType.undefined;
                    }
                }
            }
            else if (argType == ArgsTuple.ArgType.configFile)
            {
                tuple.ConfigFilePath = arg;
                nextArgIs            = ArgsTuple.ArgType.flag;
            }
            else if (argType == ArgsTuple.ArgType.logFile)
            {
                tuple.LogFilePath = arg;
                nextArgIs         = ArgsTuple.ArgType.flag;
            }
            else
            {
                nextArgIs = ArgsTuple.ArgType.undefined;
            }
            return(nextArgIs);
        }
Пример #2
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Arguments like -r, -d, -o, h or -l</param>
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(Usage(false));
                return;
            }

            ArgsTuple a = new ArgsTuple();
            Task      t = null;

            ArgsTuple.ArgType type = ArgsTuple.ArgType.flag;

            for (int i = 0; i < args.Length; i++)
            {
                type = CheckArgs(ref a, args[i], type);
                if (type == ArgsTuple.ArgType.undefined)
                {
                    Console.WriteLine("Unknown flag '" + args[i] + "'");
                    Console.WriteLine(Usage(false));
                    return;
                }
            }
            if (a.Help == true)
            {
                Console.WriteLine(Usage(false));
                return;
            }
            if (a.Docs == true)
            {
                Documentation();
                return;
            }
            if (a.Markdown == true)
            {
                Console.WriteLine(Usage(true));
                Console.WriteLine("Generating markdown files in current folder...");
                List <SubTask> types = Task.EnumerateSubTasks();
                foreach (SubTask subtask in types)
                {
                    subtask.SaveMarkdown(subtask.MarkdownFileName);
                }
                return;
            }
            if (a.Demo == true)
            {
                Console.WriteLine(Usage(true));
                Console.WriteLine("Generating demo files in current folder...");
                List <SubTask> types = Task.EnumerateSubTasks();
                foreach (SubTask subtask in types)
                {
                    Task.CreateDemoFile(subtask.DemoFileName, subtask.Type);
                }
                return;
            }
            if (a.ConfigFilePath == "" && a.Run == true)
            {
                Console.WriteLine("Error: No config file was defined");
                return;
            }
            if (a.LogFilePath == "" && a.Log == true)
            {
                Console.WriteLine("Error: No logfile path was defined");
                return;
            }
            if (a.Run == true)
            {
                if (a.Output == true)
                {
                    Console.WriteLine(Usage(true));
                }
                t = Task.Deserialize(a.ConfigFilePath);
                if (t.Valid == false)
                {
                    return;
                }
                t.Run(a.HaltOnError, a.Output, a.Log);
                if (a.Log == true)
                {
                    t.Log(a.LogFilePath);
                }
            }
        }