public void should_get_option_basic_metadata()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginCommand("command", string.Empty)
                                .AddFlagOption("flag", 'f', "flag description")
                                .AddOptionWithValue("key-value", 'k', "key value description")
                                .EndCommand()
                                .Build();

            ArgsParsingResult result = parser.Parse(new [] { "command", "--flag", "-k", "value" });

            result.AssertSuccess();

            IOptionDefinitionMetadata[] optionDefinitionMetadatas =
                result.Command.GetRegisteredOptionsMetadata().ToArray();
            IOptionDefinitionMetadata flagMetadata = optionDefinitionMetadatas
                                                     .Single(d => d.SymbolMetadata.FullForm.Equals("flag", StringComparison.OrdinalIgnoreCase));
            IOptionDefinitionMetadata kvMetadata = optionDefinitionMetadatas
                                                   .Single(d => d.SymbolMetadata.FullForm.Equals("key-value", StringComparison.OrdinalIgnoreCase));

            Assert.Equal("flag", flagMetadata.SymbolMetadata.FullForm);
            Assert.Equal('f', flagMetadata.SymbolMetadata.Abbreviation);
            Assert.Equal("flag description", flagMetadata.Description);
            Assert.Equal(OptionType.Flag, flagMetadata.Type);
            Assert.False(flagMetadata.IsRequired);

            Assert.Equal("key-value", kvMetadata.SymbolMetadata.FullForm);
            Assert.Equal('k', kvMetadata.SymbolMetadata.Abbreviation);
            Assert.Equal("key value description", kvMetadata.Description);
            Assert.Equal(OptionType.KeyValue, kvMetadata.Type);
            Assert.False(kvMetadata.IsRequired);
        }
        void should_return_empty_description_for_flag_not_defined_description()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginDefaultCommand()
                                .AddFlagOption("flag", 'f', null)
                                .EndCommand()
                                .Build();
            ArgsParsingResult result = parser.Parse(new[] { "--flag" });

            Assert.True(result.IsSuccess);
            IOptionDefinitionMetadata[] optionDefinitionMetadatas = result.Command.GetRegisteredOptionsMetadata().ToArray();
            IOptionDefinitionMetadata   flagMetadata = optionDefinitionMetadatas.Single(d => d.SymbolMetadata.FullForm.Equals("flag", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(string.Empty, flagMetadata.Description);
        }
        void should_return_null_when_get_abbreviation_of_flag_without_abbreviation()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginDefaultCommand()
                                .AddFlagOption("flag", null, null)
                                .EndCommand()
                                .Build();
            ArgsParsingResult result = parser.Parse(new[] { "--flag" });

            Assert.True(result.IsSuccess);
            IOptionDefinitionMetadata flagMetadata =
                result.Command.GetRegisteredOptionsMetadata()
                .Single(d => d.SymbolMetadata.FullForm.ToString().Equals("flag", StringComparison.OrdinalIgnoreCase));

            Assert.Null(flagMetadata.SymbolMetadata.Abbreviation);
        }
        void should_return_registed_flag_options_of_comand()
        {
            ArgsParser parser = new ArgsParserBuilder()
                                .BeginDefaultCommand()
                                .AddFlagOption("flag", 'f', "flag description")
                                .EndCommand()
                                .Build();
            ArgsParsingResult result = parser.Parse(new[] { "--flag" });

            Assert.True(result.IsSuccess);
            IOptionDefinitionMetadata[] optionDefinitionMetadatas = result.Command.GetRegisteredOptionsMetadata().ToArray();
            IOptionDefinitionMetadata   flagMetadata = optionDefinitionMetadatas.Single(d => d.SymbolMetadata.FullForm.Equals("flag", StringComparison.OrdinalIgnoreCase));

            Assert.Equal("flag", flagMetadata.SymbolMetadata.FullForm);
            Assert.Equal('f', flagMetadata.SymbolMetadata.Abbreviation);
            Assert.Equal("flag description", flagMetadata.Description);
        }
Exemple #5
0
 internal FlagArgument(IOptionDefinitionMetadata option) : base(option)
 {
 }
 protected ArgumentDefinition(IOptionDefinitionMetadata option)
 {
     Option = option;
 }