Exemplo n.º 1
0
        /// <inheritdoc />
        public override bool HandleOption(CommandLineUtilities.Option opt)
        {
            if (string.Equals("pathFormat", opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals("p", opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                Slashes = CommandLineUtilities.ParseEnumOption <PathFixer.SlashType>(opt);

                switch (Slashes)
                {
                case PathFixer.SlashType.Default:
                case PathFixer.SlashType.Unix:
                case PathFixer.SlashType.Windows:
                    break;

                default:
                    throw Contract.AssertFailure("Unexpected enum value for SlashType");
                }

                return(true);
            }

            if (string.Equals("lowerCaseDirectories", opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals("l", opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                LowerCaseDirectories = CommandLineUtilities.ParseBooleanOption(opt);
                return(true);
            }

            return(base.HandleOption(opt));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override bool HandleOption(CommandLineUtilities.Option opt)
        {
            if (string.Equals(OutputFolderOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(OutputFolderOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                OutputFolder = CommandLineUtilities.ParsePathOption(opt);
                return(true);
            }

            if (string.Equals(RootLinkOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(RootLinkOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                RootLink = CommandLineUtilities.ParseStringOption(opt);
                return(true);
            }

            if (string.Equals(CleanOutputOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(CleanOutputOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                CleanOutputFolder = CommandLineUtilities.ParseBooleanOption(opt);
                return(true);
            }

            if (string.Equals(ModuleListOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) ||
                string.Equals(ModuleListOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase))
            {
                ModuleList = new HashSet <string>(CommandLineUtilities.ParseStringOption(opt).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                return(true);
            }

            return(base.HandleOption(opt));
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public override bool HandleOption(CommandLineUtilities.Option opt)
        {
            if (m_outputFileOption.Match(opt.Name))
            {
                m_outputFile = CommandLineUtilities.ParsePathOption(opt);
                return(true);
            }

            if (m_descriptionOption.Match(opt.Name))
            {
                m_description = opt.Value;
                return(true);
            }

            if (m_alternateSymbolSeparatorOption.Match(opt.Name))
            {
                var alternateSymbolSeparatorString = CommandLineUtilities.ParseStringOption(opt);
                m_alternateSymbolSeparator = alternateSymbolSeparatorString.Length != 0
                    ? alternateSymbolSeparatorString[0]
                    : default;
                return(true);
            }

            if (m_topSortOption.Match(opt.Name))
            {
                SerializeUsingTopSort = CommandLineUtilities.ParseBooleanOption(opt);
                return(true);
            }

            return(base.HandleOption(opt));
        }
Exemplo n.º 4
0
        public void BooleanOption()
        {
            CommandLineUtilities.Option opt = default(CommandLineUtilities.Option);

            opt.Name  = "Switch";
            opt.Value = null;
            Assert.True(CommandLineUtilities.ParseBooleanOption(opt));

            opt.Name  = "Switch";
            opt.Value = string.Empty;
            Assert.True(CommandLineUtilities.ParseBooleanOption(opt));

            opt.Name  = "Switch+";
            opt.Value = null;
            Assert.True(CommandLineUtilities.ParseBooleanOption(opt));

            opt.Name  = "Switch+";
            opt.Value = string.Empty;
            Assert.True(CommandLineUtilities.ParseBooleanOption(opt));

            opt.Name  = "Switch-";
            opt.Value = null;
            Assert.False(CommandLineUtilities.ParseBooleanOption(opt));

            opt.Name  = "Switch-";
            opt.Value = string.Empty;
            Assert.False(CommandLineUtilities.ParseBooleanOption(opt));

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch+";
                opt.Value = "X";
                CommandLineUtilities.ParseBooleanOption(opt);
            });
        }
Exemplo n.º 5
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());
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override bool HandleOption(CommandLineUtilities.Option opt)
        {
            if (m_outputFileOption.Match(opt.Name))
            {
                m_outputFile = CommandLineUtilities.ParsePathOption(opt);
                return(true);
            }

            if (m_descriptionOption.Match(opt.Name))
            {
                m_description = opt.Value;
                return(true);
            }

            if (m_topSortOption.Match(opt.Name))
            {
                SerializeUsingTopSort = CommandLineUtilities.ParseBooleanOption(opt);
                return(true);
            }

            return(base.HandleOption(opt));
        }
Exemplo n.º 7
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)));
        }
Exemplo n.º 8
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 "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));
        }