Пример #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());
        }
Пример #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());
        }
Пример #3
0
        public void CommandHelp_Arguments_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)),
                new CommandArgumentDescriptor(typeof(string[]), "src", 0, "src files", CoconaDefaultValue.None, Array.Empty <Attribute>()),
                new CommandArgumentDescriptor(typeof(string), "dest", 0, "dest dir", CoconaDefaultValue.None, Array.Empty <Attribute>()),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

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

command description

Arguments:
  0: src     src files (Required)
  1: dest    dest dir (Required)

Options:
  -f, --foo <String>         Foo option (Required)
  -l, --looooooong-option    Long name option
".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());
        }
Пример #5
0
        public void CreateVersionHelp_VersionOnly()
        {
            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateVersionHelp();

            help.Children.Should().HaveCount(1);
            var text = new CoconaHelpRenderer().Render(help);

            text.Should().Be("ProductName 1.0.0.0" + Environment.NewLine);
        }
        public void Transform_CreateCommandHelp_InheritedAttribute()
        {
            var commandDescriptor = CreateCommand <TestCommand_InheritedAttribute>(
                nameof(TestCommand_InheritedAttribute.A),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: false
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), CreateServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

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

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());
        }
Пример #8
0
        public void CommandHelp_Options_Hidden_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(bool), "flag", new [] { 'f' }, "Boolean option", new CoconaDefaultValue(true), CommandOptionFlags.Hidden),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

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

command description
".TrimStart());
        }
Пример #9
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());
        }
Пример #10
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());
        }
Пример #11
0
        public void CommandHelp1()
        {
            // void Test(string arg0, string arg1, string arg2);
            // Arguments: new [] { "argValue0", "argValue1", "argValue2" }
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(string), "option0", Array.Empty <char>(), "option description - option0", CoconaDefaultValue.None),
                CreateCommandOption(typeof(bool), "option1", Array.Empty <char>(), "option description - option1", CoconaDefaultValue.None),
                new CommandIgnoredParameterDescriptor(typeof(bool), "ignored0", true),
                new CommandServiceParameterDescriptor(typeof(bool), "fromService0"),
                new CommandArgumentDescriptor(typeof(string), "arg0", 0, "description - arg0", CoconaDefaultValue.None, Array.Empty <Attribute>()),
                new CommandArgumentDescriptor(typeof(string), "arg1", 1, "description - arg1", CoconaDefaultValue.None, Array.Empty <Attribute>()),
                new CommandArgumentDescriptor(typeof(string), "arg2", 2, "description - arg2", CoconaDefaultValue.None, Array.Empty <Attribute>()),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);
        }
Пример #12
0
        public void CommandHelp_Options_Generics_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(List <int>), "option0", new [] { 'o' }, "Int option values", CoconaDefaultValue.None),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName Test [--option0 <Int32>...]

command description

Options:
  -o, --option0 <Int32>...    Int option values (Required)
".TrimStart());
        }
Пример #13
0
        public void CommandHelp_Options_Enum_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(CommandHelpEnumValue), "enum", new [] { 'e' }, "Enum option", CoconaDefaultValue.None),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor, Array.Empty <CommandDescriptor>());
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName Test [--enum <CommandHelpEnumValue>]

command description

Options:
  -e, --enum <CommandHelpEnumValue>    Enum option (Required) (Allowed values: Alice, Karen, Other)
".TrimStart());
        }
Пример #14
0
        public void CommandHelp_Options_Boolean_DefaultTrue_Rendered()
        {
            var commandDescriptor = CreateCommand(
                "Test",
                "command description",
                new ICommandParameterDescriptor[]
            {
                CreateCommandOption(typeof(bool), "flag", new [] { 'f' }, "Boolean option", new CoconaDefaultValue(true)),
            }
                );

            var provider = new CoconaCommandHelpProvider(new FakeApplicationMetadataProvider(), new ServiceCollection().BuildServiceProvider());
            var help     = provider.CreateCommandHelp(commandDescriptor);
            var text     = new CoconaHelpRenderer().Render(help);

            text.Should().Be(@"
Usage: ExeName Test [--flag=<true|false>]

command description

Options:
  -f, --flag=<true|false>    Boolean option (Default: True)
".TrimStart());
        }