コード例 #1
0
        public void Single_Command()
        {
            // $ ./app-single (build a message in the command)
            var commandProvider       = new CoconaCommandProvider(new[] { typeof(TestCommands_Single) });
            var commandCollectionRoot = commandProvider.GetCommandCollection();
            var commandStack          = Array.Empty <CommandDescriptor>();

            var targetCommand     = commandCollectionRoot.Primary;
            var commandCollection = commandCollectionRoot;

            var appContext = new CoconaAppContext(targetCommand, default);

            appContext.Features.Set <ICoconaCommandFeature>(new CoconaCommandFeature(commandCollection, targetCommand, commandStack, new object() /* unused */));
            var helpBuilder = new CoconaHelpMessageBuilder(
                new FakeAppContextAccessor(appContext),
                new FakeCommandHelpProvider(),
                new FakeHelpRenderer(),
                commandProvider
                );

            var help = helpBuilder.BuildAndRenderForCurrentCommand();

            help.Should().Be("IndexHelp;Commands=Foo;SubCommandStack="); // If the collection has only one command, a generated help is always IndexHelp.
        }
コード例 #2
0
        public void Multiple_Command()
        {
            // $ ./app-multiple Foo (call from `Foo` method)
            var commandProvider       = new CoconaCommandProvider(new[] { typeof(TestCommands_Multiple) });
            var commandCollectionRoot = commandProvider.GetCommandCollection();
            var commandStack          = Array.Empty <CommandDescriptor>();

            var targetCommand     = commandCollectionRoot.All.First(x => x.Name == "Foo");
            var commandCollection = commandCollectionRoot;

            var appContext = new CoconaAppContext(targetCommand, default);

            appContext.Features.Set <ICoconaCommandFeature>(new CoconaCommandFeature(commandCollection, targetCommand, commandStack, new object() /* unused */));
            var helpBuilder = new CoconaHelpMessageBuilder(
                new FakeAppContextAccessor(appContext),
                new FakeCommandHelpProvider(),
                new FakeHelpRenderer(),
                commandProvider
                );

            var help = helpBuilder.BuildAndRenderForCurrentCommand();

            help.Should().Be("Command;Name=Foo;SubCommandStack=");
        }