コード例 #1
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());
        }
コード例 #2
0
        public void CommandHelp_Nested_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)),
            }
                );

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

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

command description

Options:
  -f, --foo <String>         Foo option (Required)
  -l, --looooooong-option    Long name option
".TrimStart());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public void Transform_CreateCommandHelp()
        {
            var commandDescriptor = CreateCommand <TestCommand>(
                nameof(TestCommand.A),
                new ICommandParameterDescriptor[0],
                isPrimaryCommand: false
                );

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

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

command description

Hello, Konnichiwa!
".TrimStart());
        }
コード例 #5
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());
        }
コード例 #6
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);
        }
コード例 #7
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());
        }
コード例 #8
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());
        }
コード例 #9
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());
        }