public void FindDescription_GivenMemberWithDescription_ReturnsDescription()
        {
            var method      = typeof(SampleDriver).GetMethod("Debug");
            var description = CommandLineOptionBase.FindDescription(method);

            description.Should().Be("Show Diagnostics");
        }
        public void FindDescription_GivenMemberWithNoDescription_ReturnsEmptyString()
        {
            var method      = typeof(SampleDriver).GetMethod("Verbose");
            var description = CommandLineOptionBase.FindDescription(method);

            description.Should().Be(string.Empty);
        }
Пример #3
0
        private void ParseOption(CommandLineOptionBase option, CommandParserResult result)
        {
            bool found = argumentManager.TryGetValue(option, out ArgumentModel model);

            if (found && HelpRequested(result, option, model))
            {
                logger.LogDebug("Command Option '{Name}' got help requested.", option.ToString());

                return;
            }
            else if (!found && option.CheckOptionNotFound())
            {
                throw new OptionNotFoundException(option);
            }
            else if (option.ShouldUseDefault(found, model))
            {
                logger.LogDebug("Command Option '{Name}' using default value.", option.ToString());

                option.UseDefault();

                return;
            }
            else if (found && !option.CanParse(model))
            {
                throw new OptionParseException(option, model);
            }
            else if (!found)
            {
                return;
            }

            option.Parse(model);
        }
        private void ParseOption(CommandLineOptionBase option, ParseResult <TOption> result)
        {
            bool found = ArgumentManager.TryGetValue(option, out ArgumentModel model);

            if (found && HelpRequested(result, option, model))
            {
                return;
            }
            else if (!found && option.CheckOptionNotFound())
            {
                throw new OptionNotFoundException(option);
            }
            else if (option.ShouldUseDefault(found, model))
            {
                option.UseDefault();

                return;
            }
            else if (found && !option.CanParse(model))
            {
                throw new OptionParseException(option, model);
            }
            else if (!found)
            {
                return;
            }

            option.Parse(model);
        }
        private bool HelpRequested(CommandParserResult result, CommandLineOptionBase option, ArgumentModel model)
        {
            if (!m_parserOptions.EnableHelpOption)
            {
                return(false);
            }

            if (model.Key.Equals(m_helpOptionName, StringComparison.InvariantCultureIgnoreCase) ||
                model.Key.Equals(m_helpOptionNameLong, StringComparison.InvariantCultureIgnoreCase))
            {
                result.HelpRequestedFor = this;

                return(true);
            }
            else if (model.HasValue &&
                     (model.Value.Equals(m_helpOptionName, StringComparison.InvariantCultureIgnoreCase) ||
                      model.Value.Equals(m_helpOptionNameLong, StringComparison.InvariantCultureIgnoreCase)))
            {
                result.HelpRequestedFor = option;

                return(true);
            }

            return(false);
        }