Ejemplo n.º 1
0
        public CommandLineOptions(string[] args)
        {
            ConfigFile   = "cronical.dat";
            ServiceName  = "Cronical";
            ServiceTitle = "Cronical Job Scheduler";

            var arglist = args.ToList();

            while (arglist.Any())
            {
                var s = arglist.ExtractFirst().ToLower();

                switch (s)
                {
                case "-d":
                case "--debug":
                    DebugLogs = true;
                    break;

                case "--console":
                    RunAsConsole = true;
                    break;

                case "-c":
                case "--config":
                    ConfigFileOverride = true;
                    ConfigFile         = arglist.ExtractFirstOrDefault();
                    if (string.IsNullOrEmpty(ConfigFile) || ConfigFile.StartsWith("-"))
                    {
                        throw new Exception("Expected file name to follow on --config");
                    }
                    break;

                case "-h":
                case "--help":
                case "-?":
                case "/h":
                case "/help":
                    DisplayHelp();
                    throw new OperationCanceledException();

                case "--install":
                    InstallService = true;
                    break;

                case "--remove":
                    RemoveService = true;
                    break;

                case "--service-name":
                    ServiceName = arglist.ExtractFirstOrDefault();
                    if (string.IsNullOrEmpty(ServiceName) || ServiceName.StartsWith("-"))
                    {
                        throw new Exception("Expected name to follow after --service-name");
                    }
                    break;

                case "--service-title":
                    ServiceTitle = arglist.ExtractFirstOrDefault();
                    if (string.IsNullOrEmpty(ServiceTitle) || ServiceTitle.StartsWith("-"))
                    {
                        throw new Exception("Expected text to follow after --service-title");
                    }
                    break;

                case "--service-desc":
                    ServiceDescription = arglist.ExtractFirstOrDefault();
                    if (string.IsNullOrEmpty(ServiceDescription) || ServiceDescription.StartsWith("-"))
                    {
                        throw new Exception("Expected name to follow after --service-desc");
                    }
                    break;

                default:
                    throw new Exception("Unrecognized option " + s);
                }
            }
        }