Beispiel #1
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));
        }
        /// <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));
        }
        public void RepeatingPathOption()
        {
            CommandLineUtilities.Option opt = default(CommandLineUtilities.Option);

            opt.Name  = "Switch";
            opt.Value = "test.dll";
            Assert.True(
                CommandLineUtilities.ParseRepeatingPathOption(opt, ",").SequenceEqual(
                    new string[]
            {
                Path.Combine(Directory.GetCurrentDirectory(), "test.dll")
            }));

            opt.Name  = "Switch";
            opt.Value = "test.dll,test2.dll";
            Assert.True(
                CommandLineUtilities.ParseRepeatingPathOption(opt, ",").SequenceEqual(
                    new string[]
            {
                Path.Combine(Directory.GetCurrentDirectory(), "test.dll"),
                Path.Combine(Directory.GetCurrentDirectory(), "test2.dll")
            }));

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = null;
                CommandLineUtilities.ParseStringOption(opt);
            });
        }
        public void StringOption()
        {
            CommandLineUtilities.Option opt = default(CommandLineUtilities.Option);

            opt.Name  = "Switch";
            opt.Value = "Value";
            Assert.Equal(opt.Value, CommandLineUtilities.ParseStringOption(opt));

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = null;
                CommandLineUtilities.ParseStringOption(opt);
            });

            Assert.Throws <InvalidArgumentException>(() =>
            {
                opt.Name  = "Switch";
                opt.Value = string.Empty;
                CommandLineUtilities.ParseStringOption(opt);
            });
        }
Beispiel #5
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)));
        }
Beispiel #6
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));
        }