Exemplo n.º 1
0
        public void CommandIndexHelp_Single_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(string), "foo", new [] { 'f' }, "Foo option", CoconaDefaultValue.None),
                CreateCommandOption(typeof(bool), "looooooong-option", new [] { 'l' }, "Long name option", new CoconaDefaultValue(false)),
            },
                CommandFlags.Primary
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor }), Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName [--foo <String>] [--looooooong-option]

command description

Options:
  -f, --foo <String>         Foo option (Required)
  -l, --looooooong-option    Long name option
".TrimStart());
        }
Exemplo n.º 2
0
        public void CreateCommandsIndexHelp_Commands_Hidden_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[0],
                CommandFlags.Hidden
                );
            var commandDescriptor2 = CreateCommand(
                "Test2",
                "command2 description",
                new ICommandParameterDescriptor[0],
                CommandFlags.None
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor, commandDescriptor2 }), Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName [command]

Commands:
  Test2    command2 description
".TrimStart());
        }
        public void Transform_CreateCommandsIndexHelp_Primary_Class_InheritedAttribute()
        {
            var commandDescriptor = CreateCommand <TestCommand_Primary_InheritedAttribute>(
                nameof(TestCommand_Primary_InheritedAttribute.Default),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: true
                );
            var commandDescriptor1 = CreateCommand <TestCommand_Primary_InheritedAttribute>(
                nameof(TestCommand_Primary_InheritedAttribute.A),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: false
                );
            var commandDescriptor2 = CreateCommand <TestCommand_Primary_InheritedAttribute>(
                nameof(TestCommand_Primary_InheritedAttribute.B),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: false
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), CreateServiceProvider());
            var help     = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor, commandDescriptor1, commandDescriptor2 }), Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName [command]

command description

Commands:
  A    command description
  B    command description

Hi!
".TrimStart());
        }
        public void Transform_CreateCommandsIndexHelp()
        {
            var commandDescriptor = CreateCommand <TestCommand>(
                nameof(TestCommand.A),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: true
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), CreateServiceProvider());
            var help     = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor }), Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName

command description

Hello, Konnichiwa!
".TrimStart());
        }
Exemplo n.º 5
0
        public void CreateCommandsIndexHelp_Nested_Commands_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(string), "foo", new [] { 'f' }, "Foo option", CoconaDefaultValue.None),
                CreateCommandOption(typeof(bool), "looooooong-option", new [] { 'l' }, "Long name option", new CoconaDefaultValue(false)),
                CreateCommandOption(typeof(int), "bar", new [] { 'b' }, "has default value", new CoconaDefaultValue(123)),
            },
                CommandFlags.Primary
                );
            var commandDescriptor2 = CreateCommand(
                "Test2",
                "command2 description",
                new ICommandParameterDescriptor[0],
                CommandFlags.None
                );

            var subCommandStack = new[] { CreateCommand("Nested", "", Array.Empty <ICommandParameterDescriptor>()) };
            var provider        = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help            = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor, commandDescriptor2 }), subCommandStack);
            var text            = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName Nested [command]
Usage: ExeName Nested [--foo <String>] [--looooooong-option] [--bar <Int32>]

command description

Commands:
  Test2    command2 description

Options:
  -f, --foo <String>         Foo option (Required)
  -l, --looooooong-option    Long name option
  -b, --bar <Int32>          has default value (Default: 123)
".TrimStart());
        }
Exemplo n.º 6
0
        public void CommandIndexHelp_Single_NoParams_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "",
                new ICommandParameterDescriptor[0],
                CommandFlags.Primary
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider()
            {
                Description = "via metadata"
            }, new ServiceCollection().BuildServiceProvider());
            var help = provider.CreateCommandsIndexHelp(new CommandCollection(new[] { commandDescriptor }), Array.Empty <CommandDescriptor>());
            var text = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName

via metadata
".TrimStart());
        }