public void AddingTwoOptionsWithSameNameShouldThrow()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("foo");
            Should.Throw<InvalidOperationException>(() => builder.Option("Foo"));
        }
 public void AddingTwoOptionValuesWithTheSameNameShouldThrow()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     var optionDefinitionBuilder = builder.Option("option");
     optionDefinitionBuilder.Value("value");
     Should.Throw<InvalidOperationException>(() => optionDefinitionBuilder.Value("value"));
 }
 public void AddingOptionValueWithNameEqualToNullOrWhiteSpaceShouldThrow()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     var optionDefinitionBuilder = builder.Option("option");
     Should.Throw<ArgumentException>(() => optionDefinitionBuilder.Value(null));
     Should.Throw<ArgumentException>(() => optionDefinitionBuilder.Value(string.Empty));
     Should.Throw<ArgumentException>(() => optionDefinitionBuilder.Value(" "));
 }
 public void ShouldParseFlagOption()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name");
     var settings = new CmdLineSettings();
     var parser = new CmdLineParser(builder.Definition, settings);
     var input = parser.Parse(new[] { "-name" });
     input.Options.Contains("name").ShouldBe(true);
 }
 public void ShouldParseOptionsWithSeparatedFormat()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name").Value("value");
     var settings = new CmdLineSettings { OptionValueFormat = OptionValueFormat.Separated };
     var parser = new CmdLineParser(builder.Definition, settings);
     var input = parser.Parse("-name", "foo");
     input.Options.GetSingle("name").GetSingle("value").ShouldBe("foo");
 }
 public void ShouldParseOptionWithParamsValue()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name")
            .Value("value", x => x.IsParams());
     var settings = new CmdLineSettings();
     var parser = new CmdLineParser(builder.Definition, settings);
     var input = parser.Parse("-name:foo;bar");
     input.Options.GetSingle("name").GetAll("value").ShouldBe(new[] { "foo", "bar" });
 }
 public void ShouldParseMultipleInstancesOfAllowMultipleOption()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name")
            .AllowMultiple()
            .Value("value");
     var settings = new CmdLineSettings();
     var parser = new CmdLineParser(builder.Definition, settings);
     var input = parser.Parse("-name:foo", "-name:bar");
     var options = input.Options.GetAll("name");
     options.Length.ShouldBe(2);
     options[0].GetSingle("value").ShouldBe("foo");
     options[1].GetSingle("value").ShouldBe("bar");
 }
 public void ShouldThrowIfRequiredOptionValueIsntProvided()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name").IsRequired().Value("value");
     var settings = new CmdLineSettings();
     var parser = new CmdLineParser(builder.Definition, settings);
     Should.Throw<ParserException>(() => parser.Parse("-name"));
 }
 public void ShouldThrowIfFlagOptionHasValue()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     builder.Option("name");
     var settings = new CmdLineSettings();
     var parser = new CmdLineParser(builder.Definition, settings);
     Should.Throw<ParserException>(() => parser.Parse(new[] { "-name:value" }));
 }
        public void ConfiguredOptionValueShouldHaveCorrectConfiguration()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("option")
                   .Value("value", x => x.IsOptional().IsParams().Description("description").DisplayName("displayName"));

            CmdLineOptionDefinition optionDefinition;
            builder.TryGetOption("option", out optionDefinition);
            var definition = optionDefinition.Values.First();
            definition.Name.ShouldBe("value");
            definition.IsOptional.ShouldBe(true);
            definition.IsParams.ShouldBe(true);
            definition.DisplayName.ShouldBe("displayName");

            var writer = new TestWriter();
            definition.DescriptionWriter(definition, writer, 0);
            writer.ToString().ShouldBe("description" + Environment.NewLine);
        }
        public void UnconfiguredOptionShouldHaveCorrectDefaultConfiguration()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("foo");

            CmdLineOptionDefinition definition;
            builder.TryGetOption("foo", out definition);
            definition.Name.ShouldBe("foo");
            definition.AllowMultiple.ShouldBe(false);
            definition.IsRequired.ShouldBe(false);
            definition.DescriptionWriter.ShouldBe(null);
            definition.Shortcut.ShouldBe(null);
            definition.Values.ShouldBeEmpty();
        }
        public void ShouldBeAbleToEnumerateAddedOptions()
        {
            var builder = new CmdLineInputDefinitionBuilder();
            builder.Option("foo");
            builder.Option("bar");

            builder.Definition.Options.Select(x => x.Name).ShouldBe(new[] { "foo", "bar" });
        }
 public void OptionValueThatIsParamsShouldBeTheLastArg()
 {
     var builder = new CmdLineInputDefinitionBuilder();
     var optionDefinitionBuilder = builder.Option("option");
     optionDefinitionBuilder.Value("value1", x => x.IsParams());
     Should.Throw<InvalidOperationException>(() => optionDefinitionBuilder.Value("value2"));
 }
        public void OptionValuesShouldBeAccessibleInTheSameOrderTheyWereAdded()
        {
            var builder = new CmdLineInputDefinitionBuilder();
            builder.Option("option")
                   .Value("value1")
                   .Value("value2");

            builder.Definition.Options.First().Values.Select(x => x.Name).ShouldBe(new[] { "value1", "value2" });
        }
        public void OptionRetievalShouldBeCaseInsensitive()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("foo");

            CmdLineOptionDefinition optionDefinition;

            builder.TryGetOption("foo", out optionDefinition).ShouldBe(true);
            optionDefinition.Name.ShouldBe("foo");

            builder.TryGetOption("Foo", out optionDefinition).ShouldBe(true);
            optionDefinition.Name.ShouldBe("foo");
        }
        public void UnconfiguredOptionValueShouldHaveCorrectDefaultConfiguration()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("foo")
                   .Value("bar");

            CmdLineOptionDefinition optionDefinition;
            builder.TryGetOption("foo", out optionDefinition);
            var valueDefinition = optionDefinition.Values.First();
            valueDefinition.Name.ShouldBe("bar");
            valueDefinition.IsOptional.ShouldBe(false);
            valueDefinition.IsParams.ShouldBe(false);
            valueDefinition.DescriptionWriter.ShouldBe(null);
            valueDefinition.DisplayName.ShouldBe(null);
        }
        public void ConfiguredOptionShouldHaveCorrectConfiguration()
        {
            var builder = new CmdLineInputDefinitionBuilder();

            builder.Option("noValueOption")
                   .AllowMultiple()
                   .IsRequired()
                   .Description("description")
                   .ShortCut("nvo");

            CmdLineOptionDefinition definition;
            builder.TryGetOption("noValueOption", out definition);
            definition.Name.ShouldBe("noValueOption");
            definition.AllowMultiple.ShouldBe(true);
            definition.IsRequired.ShouldBe(true);
            definition.Shortcut.ShouldBe("nvo");

            var writer = new TestWriter();
            definition.DescriptionWriter(definition, writer, 0);
            writer.ToString().ShouldBe("description" + Environment.NewLine);
        }