public void should_get_option_raw_value_for_multiple_def_in_default_command() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("key-a", 'a', string.Empty) .AddOptionWithValue("key-b", 'b', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "--key-a", "value-a", "-b", "value-b" }); result.AssertSuccess(); Assert.Equal("value-a", result.GetOptionRawValue("-a").Single()); Assert.Equal("value-b", result.GetOptionRawValue("--key-b").Single()); }
public void should_get_option_raw_value_with_default_command() { // waiting-value -(any)-> ok ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("key", 'k', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "--key", "value" }); result.AssertSuccess(); Assert.Equal("value", result.GetOptionRawValue("--key").First()); Assert.Equal("value", result.GetOptionRawValue("-k").First()); }
public void should_get_option_raw_value_even_if_value_looks_like_options_keys(string optionLikeValue) { // waiting-value -(any)-> ok ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("key", 'k', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "--key", optionLikeValue }); result.AssertSuccess(); Assert.Equal(optionLikeValue, result.GetOptionRawValue("--key").First()); Assert.Equal(optionLikeValue, result.GetOptionRawValue("-k").First()); Assert.Throws <ArgumentException>(() => result.GetOptionRawValue("--value")); Assert.Throws <ArgumentException>(() => result.GetOptionRawValue("-v")); }
public void should_get_option_raw_value_for_specified_command() { ArgsParser parser = new ArgsParserBuilder() .BeginCommand("command", string.Empty) .AddOptionWithValue("key", 'k', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new [] { "command", "-k", "value" }); result.AssertSuccess(); Assert.Equal("value", result.GetOptionRawValue("--key").Single()); }
public void should_get_non_required_optional_raw_value() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("key", 'k', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(Array.Empty <string>()); result.AssertSuccess(); Assert.Empty(result.GetOptionRawValue("--key")); }
public void should_throw_if_getting_option_from_a_failure_result() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("option", 'o', string.Empty, true) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new string[0]); Assert.False(result.IsSuccess); Assert.Throws <InvalidOperationException>(() => result.GetOptionRawValue("-o")); Assert.Throws <InvalidOperationException>(() => result.GetOptionValue("-o")); }
public void should_throw_if_option_is_not_defined_when_getting_option_value() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("option", 'o', string.Empty, true) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "-o", "value" }); result.AssertSuccess(); Assert.Throws <ArgumentException>(() => result.GetOptionRawValue("--not-defined")); Assert.Throws <ArgumentException>(() => result.GetOptionValue("--not-defined")); }
public void should_get_mixed_options_for_default_command() { ArgsParser parser = new ArgsParserBuilder() .BeginDefaultCommand() .AddOptionWithValue("key-a", 'a', string.Empty) .AddFlagOption("flag-b", 'b', string.Empty) .AddFlagOption("flag-c", 'c', string.Empty) .EndCommand() .Build(); ArgsParsingResult result = parser.Parse(new[] { "--key-a", "value", "-b" }); result.AssertSuccess(); Assert.Equal("value", result.GetOptionRawValue("-a").Single()); Assert.True(result.GetFlagValue("--flag-b")); Assert.False(result.GetFlagValue("--flag-c")); }