Beispiel #1
0
        public void Multiple_1()
        {
            var commandCollection = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary", new ICommandParameterDescriptor[] {}, true),
                CreateCommand("Foo", new ICommandParameterDescriptor[]
                {
                    new CommandOptionDescriptor(
                        typeof(int),
                        "opt1",
                        Array.Empty <char>(),
                        "",
                        CoconaDefaultValue.None,
                        null,
                        CommandOptionFlags.None,
                        Array.Empty <Attribute>()
                        ),
                }, false),
                CreateCommand("Bar", new ICommandParameterDescriptor[] {}, false),
            });
            var resolver = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { "Foo", "--opt1", "123" });

            resolve.Success.Should().BeTrue();
            resolve.MatchedCommand.Name.Should().Be("Foo");
            resolve.ParsedCommandLine.Options.Should().HaveCount(1);
        }
Beispiel #2
0
        public void OptionLikeCommand_Single_Primary_1()
        {
            var optLikeCmd1 = CreateOptionLikeCommand("optlikecmd1", Array.Empty <char>(), "OptLikeCmd1");
            var optLikeCmd2 = CreateOptionLikeCommand("optlikecmd2", Array.Empty <char>(), "OptLikeCmd2");

            var commandCollection = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary", new ICommandParameterDescriptor[] {},
                              new CommandOptionLikeCommandDescriptor[]
                {
                    optLikeCmd1,
                },
                              true),
            });
            var resolver = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { "--optlikecmd1", "Foo", "--opt1", "123", "--help", "--version" });

            resolve.Success.Should().BeTrue();
            resolve.CommandCollection.Should().Be(commandCollection);
            resolve.MatchedCommand.Name.Should().Be("OptLikeCmd1");
            resolve.ParsedCommandLine.Options.Should().BeEmpty();
            resolve.ParsedCommandLine.UnknownOptions.Should().HaveCount(3);
        }
Beispiel #3
0
        public void Empty()
        {
            var commandCollection = new CommandCollection(new CommandDescriptor[] { });
            var resolver          = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { });

            resolve.Success.Should().BeFalse();
        }
Beispiel #4
0
        public void OptionLikeCommand_Multiple_Primary_1()
        {
            var optLikeCmd1 = CreateOptionLikeCommand("optlikecmd1", Array.Empty <char>(), "OptLikeCmd1");
            var optLikeCmd2 = CreateOptionLikeCommand("optlikecmd2", Array.Empty <char>(), "OptLikeCmd2");

            var commandCollection = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary", new ICommandParameterDescriptor[] {},
                              new CommandOptionLikeCommandDescriptor[]
                {
                    optLikeCmd1,
                },
                              true),
                CreateCommand("Foo", new ICommandParameterDescriptor[]
                {
                    new CommandOptionDescriptor(
                        typeof(int),
                        "opt1",
                        Array.Empty <char>(),
                        "",
                        CoconaDefaultValue.None,
                        null,
                        CommandOptionFlags.None,
                        Array.Empty <Attribute>()
                        ),
                }, new CommandOptionLikeCommandDescriptor[]
                {
                    optLikeCmd2
                },
                              false),
                CreateCommand("Bar", new ICommandParameterDescriptor[] {}, false),
            });
            var resolver = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { "--optlikecmd1", "Foo", "--opt1", "123", "--help", "--version" });

            resolve.Success.Should().BeTrue();
            resolve.CommandCollection.Should().Be(commandCollection);
            resolve.MatchedCommand.Name.Should().Be("OptLikeCmd1");
            resolve.ParsedCommandLine.Options.Should().BeEmpty();
            resolve.ParsedCommandLine.UnknownOptions.Should().HaveCount(3);
            resolve.SubCommandStack.Should().HaveCount(1);
        }
Beispiel #5
0
        public void Single()
        {
            var commandCollection = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary", new ICommandParameterDescriptor[] {}, true),
            });
            var resolver = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { });

            resolve.Success.Should().BeTrue();
            resolve.MatchedCommand.Name.Should().Be("Primary");
        }
Beispiel #6
0
        public void OptionLikeCommand_Multiple_SubCommand_Nested()
        {
            var optLikeCmd1             = CreateOptionLikeCommand("optlikecmd1", Array.Empty <char>(), "OptLikeCmd1");
            var optLikeCmd2             = CreateOptionLikeCommand("optlikecmd2", Array.Empty <char>(), "OptLikeCmd2");
            var commandCollectionNested = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary", new ICommandParameterDescriptor[] {}, true),
                CreateCommand("Level2", new ICommandParameterDescriptor[] { },
                              new CommandOptionLikeCommandDescriptor[] { optLikeCmd1, optLikeCmd2, },
                              false),
            });
            var commandCollection = new CommandCollection(new CommandDescriptor[]
            {
                CreateCommand("Primary",
                              new ICommandParameterDescriptor[] {},
                              null,
                              null,
                              CommandFlags.SubCommandsEntryPoint),
                CreateCommand("Level1",
                              new ICommandParameterDescriptor[] {},
                              null,
                              commandCollectionNested,
                              CommandFlags.None),
            });
            var resolver = new CoconaCommandResolver(
                new TestCommandProvider(commandCollection),
                new CoconaCommandLineParser(),
                new CoconaCommandMatcher()
                );

            var resolve = resolver.ParseAndResolve(new string[] { "Level1", "Level2", "--opt1", "123", "--optlikecmd1", "--version" });

            resolve.Success.Should().BeTrue();
            resolve.CommandCollection.Should().Be(commandCollectionNested);
            resolve.MatchedCommand.Name.Should().Be("OptLikeCmd1");
            resolve.ParsedCommandLine.Options.Should().BeEmpty();
            resolve.ParsedCommandLine.UnknownOptions.Should().HaveCount(1);
            resolve.SubCommandStack.Should().HaveCount(2);
            resolve.SubCommandStack[0].Name.Should().Be("Level1");
            resolve.SubCommandStack[1].Name.Should().Be("Level2");
        }