コード例 #1
0
        private static Options ParseOptions(string[] toolArgs)
        {
            var opts = new OptionsBuilder(Options.Defaults);

            var cli = new CommandLineUtilities(toolArgs);

            foreach (var opt in cli.Options)
            {
                switch (opt.Name.TrimEnd('-', '+'))
                {
                case ArgVerbose:
                case "v":
                    opts.Verbose = CommandLineUtilities.ParseBooleanOption(opt);
                    break;

                case ArgLogToStdOut:
                case "o":
                    opts.LogToStdOut = CommandLineUtilities.ParseBooleanOption(opt);
                    break;

                case "numKextConnections":
                case "c":
                    Console.WriteLine($"*** WARNING *** option /{opt.Name} has no effect any longer");
                    break;

                case ArgReportQueueSizeMB:
                case "r":
                    opts.ReportQueueSizeMB = CommandLineUtilities.ParseUInt32Option(opt, 1, 1024);
                    break;

                case ArgEnableReportBatching:
                case "b":
                    opts.EnableReportBatching = CommandLineUtilities.ParseBooleanOption(opt);
                    break;

                case ArgEnableStatistics:
                case "s":
                    opts.EnableTelemetry = CommandLineUtilities.ParseBooleanOption(opt);
                    break;

                case ArgProcessTimeout:
                case "t":
                    // Max is currently set to 4 hours and should suffice
                    opts.ProcessTimeout = CommandLineUtilities.ParseInt32Option(opt, (int)s_defaultProcessTimeOut, (int)s_defaultProcessTimeOutMax);
                    break;

                case ArgTrackDirectoryCreation:
                case "d":
                    opts.TrackDirectoryCreation = CommandLineUtilities.ParseBooleanOption(opt);
                    break;

                default:
                    throw new InvalidArgumentException($"Unrecognized option {opt.Name}");
                }
            }

            return(opts.Finish());
        }
コード例 #2
0
        public void Int32Option()
        {
            CommandLineUtilities.Option opt = default(CommandLineUtilities.Option);

            opt.Name  = "Switch";
            opt.Value = "12";
            Assert.Equal(12, CommandLineUtilities.ParseInt32Option(opt, 0, 100));

            opt.Name  = "Switch";
            opt.Value = "0";
            Assert.Equal(0, CommandLineUtilities.ParseInt32Option(opt, 0, 100));

            opt.Name  = "Switch";
            opt.Value = "100";
            Assert.Equal(100, CommandLineUtilities.ParseInt32Option(opt, 0, 100));

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = null;
                CommandLineUtilities.ParseInt32Option(opt, 0, 100);
            });

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = string.Empty;
                CommandLineUtilities.ParseInt32Option(opt, 0, 100);
            });

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = "-1";
                CommandLineUtilities.ParseInt32Option(opt, 0, 100);
            });

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = "101";
                CommandLineUtilities.ParseInt32Option(opt, 0, 100);
            });
        }
コード例 #3
0
        /// <summary>
        /// Attempts to parse the configuration. This is a subset of what's parsed in Args
        /// </summary>
        /// <remarks>
        /// Keep the subset of parsing here limited to whatever's needed to run the client process
        /// </remarks>
        public static bool TryParse(string[] args, out LightConfig lightConfig)
        {
            lightConfig = new LightConfig();

            var cl = new CommandLineUtilities(args);

            foreach (var option in cl.Options)
            {
                switch (option.Name.ToUpperInvariant())
                {
                case "C":
                case "CONFIG":
                    lightConfig.Config = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "COLOR":
                case "COLOR+":
                case "COLOR-":
                    lightConfig.Color = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "DISABLEPATHTRANSLATION":
                    lightConfig.DisablePathTranslation = true;
                    break;

                case "HELP":
                    lightConfig.Help = Args.ParseHelpOption(option);
                    break;

                case "NOLOGO":
                case "NOLOGO+":
                case "NOLOGO-":
                    lightConfig.NoLogo = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "FANCYCONSOLE":
                case "FANCYCONSOLE+":
                case "FANCYCONSOLE-":
                case "EXP:FANCYCONSOLE":
                case "EXP:FANCYCONSOLE+":
                case "EXP:FANCYCONSOLE-":
                    lightConfig.FancyConsole = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "ENABLEDEDUP":
                case "ENABLEDEDUP+":
                case "ENABLEDEDUP-":
                    lightConfig.EnableDedup = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "HASHTYPE":
                    lightConfig.HashType = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "SERVER":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, true, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVER+":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, true, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVER-":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, false, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVERMAXIDLETIMEINMINUTES":
                    lightConfig.ServerIdleTimeInMinutes = CommandLineUtilities.ParseInt32Option(option, 1, int.MaxValue);
                    break;

                case "SERVERDEPLOYMENTDIR":
                    lightConfig.ServerDeploymentDirectory = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "SUBSTSOURCE":
                    lightConfig.SubstSource = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "SUBSTTARGET":
                    lightConfig.SubstTarget = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "RUNINSUBST":
                case "RUNINSUBST+":
                    lightConfig.RunInSubst = true;
                    break;

                case "RUNINSUBST-":
                    lightConfig.RunInSubst = false;
                    break;
                }
            }

            // This has no attempt at any sort of error handling. Leave that to the real argument parser. Only detect errors
            // If RunInSubst is specified without an explicit subst source, we fail if the config file does not exist since we need to compute the parent directory of the main config during light config interpretation
            return(!string.IsNullOrWhiteSpace(lightConfig.Config) && (!lightConfig.RunInSubst || !string.IsNullOrEmpty(lightConfig.SubstSource) || File.Exists(lightConfig.Config)));
        }
コード例 #4
0
ファイル: LightConfig.cs プロジェクト: uilit/BuildXL
        /// <summary>
        /// Attempts to parse the configuration. This is a subset of what's parsed in Args
        /// </summary>
        /// <remarks>
        /// Keep the subset of parsing here limited to whatever's needed to run the client process
        /// </remarks>
        public static bool TryParse(string[] args, out LightConfig lightConfig)
        {
            lightConfig = new LightConfig();

            var cl = new CommandLineUtilities(args);

            foreach (var option in cl.Options)
            {
                switch (option.Name.ToUpperInvariant())
                {
                case "C":
                case "CONFIG":
                    lightConfig.Config = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "COLOR":
                case "COLOR+":
                case "COLOR-":
                    lightConfig.Color = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "DISABLEPATHTRANSLATION":
                    lightConfig.DisablePathTranslation = true;
                    break;

                case "HELP":
                    lightConfig.Help = Args.ParseHelpOption(option);
                    break;

                case "NOLOGO":
                case "NOLOGO+":
                case "NOLOGO-":
                    lightConfig.NoLogo = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "FANCYCONSOLE":
                case "FANCYCONSOLE+":
                case "FANCYCONSOLE-":
                case "EXP:FANCYCONSOLE":
                case "EXP:FANCYCONSOLE+":
                case "EXP:FANCYCONSOLE-":
                    lightConfig.FancyConsole = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "ENABLEDEDUP":
                case "ENABLEDEDUP+":
                case "ENABLEDEDUP-":
                    lightConfig.EnableDedup = CommandLineUtilities.ParseBooleanOption(option);
                    break;

                case "SERVER":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, true, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVER+":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, true, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVER-":
                    lightConfig.Server = CommandLineUtilities.ParseBoolEnumOption(option, false, ServerMode.Enabled, ServerMode.Disabled);
                    break;

                case "SERVERMAXIDLETIMEINMINUTES":
                    lightConfig.ServerIdleTimeInMinutes = CommandLineUtilities.ParseInt32Option(option, 1, int.MaxValue);
                    break;

                case "SERVERDEPLOYMENTDIR":
                    lightConfig.ServerDeploymentDirectory = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "SUBSTSOURCE":
                    lightConfig.SubstSource = CommandLineUtilities.ParseStringOption(option);
                    break;

                case "SUBSTTARGET":
                    lightConfig.SubstTarget = CommandLineUtilities.ParseStringOption(option);
                    break;
                }
            }

            // This has no attempt at any sort of error handling. Leave that to the real argument parser. Only detect errors
            return(!string.IsNullOrWhiteSpace(lightConfig.Config));
        }