public void Nested_Context_Command_Nested() { // $ ./app-nested TestCommands_Nested_1 Baz --help var commandProvider = new CoconaCommandProvider(new[] { typeof(TestCommands_Nested) }); var commandCollectionRoot = commandProvider.GetCommandCollection(); var commandNested = commandCollectionRoot.All.First(x => x.Name == "TestCommands_Nested_1"); var commandBaz = commandNested.SubCommands.All.First(x => x.Name == "Baz"); var commandStack = new[] { commandNested, commandBaz }; // --help (OptionLikeCommand) pushes the command to the stack. var targetCommand = BuiltInOptionLikeCommands.Help.Command; var commandCollection = commandNested.SubCommands; 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.BuildAndRenderForCurrentContext(); help.Should().Be("Command;Name=Baz;SubCommandStack=TestCommands_Nested_1"); }
public void Multiple_Context_Index() { // $ ./app-multiple --help var commandProvider = new CoconaCommandProvider(new[] { typeof(TestCommands_Multiple) }); var commandCollectionRoot = commandProvider.GetCommandCollection(); var commandStack = Array.Empty <CommandDescriptor>(); var targetCommand = BuiltInPrimaryCommand.GetCommand(string.Empty); // `TestCommands_Multiple` has no primary command. Use BuiltInPrimaryCommand. 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.BuildAndRenderForCurrentContext(); help.Should().Be("IndexHelp;Commands=Foo,Bar;SubCommandStack="); }
public void Single() { // $ ./app-single --help var commandProvider = new CoconaCommandProvider(new[] { typeof(TestCommands_Single) }); var commandCollectionRoot = commandProvider.GetCommandCollection(); var commandStack = new[] { commandCollectionRoot.All.First() }; // --help (OptionLikeCommand) pushes the command to the stack. var targetCommand = BuiltInOptionLikeCommands.Help.Command; 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.BuildAndRenderForCurrentContext(); help.Should().Be("IndexHelp;Commands=Foo;SubCommandStack="); // If the collection has only one command, a generated help is always IndexHelp. }