Move Spectre.Console.Cli to it's own package

This commit is contained in:
Patrik Svensson
2022-05-14 22:56:36 +02:00
committed by Patrik Svensson
parent b600832e00
commit 36ca22ffac
262 changed files with 736 additions and 48 deletions

View File

@ -0,0 +1,14 @@
namespace Spectre.Console.Tests.Data;
public abstract class AnimalSettings : CommandSettings
{
[CommandOption("-a|--alive|--not-dead")]
[Description("Indicates whether or not the animal is alive.")]
public bool IsAlive { get; set; }
[CommandArgument(1, "[LEGS]")]
[Description("The number of legs.")]
[EvenNumberValidator("Animals must have an even number of legs.")]
[PositiveNumberValidator("Number of legs must be greater than 0.")]
public int Legs { get; set; }
}

View File

@ -0,0 +1,19 @@
namespace Spectre.Console.Tests.Data;
public sealed class ArgumentOrderSettings : CommandSettings
{
[CommandArgument(0, "[QUX]")]
public int Qux { get; set; }
[CommandArgument(3, "<CORGI>")]
public int Corgi { get; set; }
[CommandArgument(1, "<BAR>")]
public int Bar { get; set; }
[CommandArgument(2, "<BAZ>")]
public int Baz { get; set; }
[CommandArgument(0, "<FOO>")]
public int Foo { get; set; }
}

View File

@ -0,0 +1,7 @@
namespace Spectre.Console.Tests.Data;
public class ArgumentVectorSettings : CommandSettings
{
[CommandArgument(0, "<Foos>")]
public string[] Foo { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace Spectre.Console.Tests.Data;
public class BarCommandSettings : FooCommandSettings
{
[CommandArgument(0, "<CORGI>")]
[Description("The corgi value.")]
public string Corgi { get; set; }
}

View File

@ -0,0 +1,11 @@
namespace Spectre.Console.Tests.Data;
public class CatSettings : MammalSettings
{
[CommandOption("--agility <VALUE>")]
[TypeConverter(typeof(CatAgilityConverter))]
[DefaultValue(10)]
[Description("The agility between 0 and 100.")]
[PositiveNumberValidator("Agility cannot be negative.")]
public int Agility { get; set; }
}

View File

@ -0,0 +1,20 @@
namespace Spectre.Console.Tests.Data;
public sealed class DogSettings : MammalSettings
{
[CommandArgument(0, "<AGE>")]
public int Age { get; set; }
[CommandOption("-g|--good-boy")]
public bool GoodBoy { get; set; }
public override ValidationResult Validate()
{
if (Name == "Tiger")
{
return ValidationResult.Error("Tiger is not a dog name!");
}
return ValidationResult.Success();
}
}

View File

@ -0,0 +1,5 @@
namespace Spectre.Console.Tests.Data;
public sealed class EmptySettings : CommandSettings
{
}

View File

@ -0,0 +1,8 @@
namespace Spectre.Console.Tests.Data;
public class FooCommandSettings : CommandSettings
{
[CommandArgument(0, "[QUX]")]
[Description("The qux value.")]
public string Qux { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace Spectre.Console.Tests.Data;
public sealed class GiraffeSettings : MammalSettings
{
[CommandArgument(0, "<LENGTH>")]
[Description("The option description.")]
public int Length { get; set; }
}

View File

@ -0,0 +1,16 @@
namespace Spectre.Console.Tests.Data;
public sealed class HiddenOptionSettings : CommandSettings
{
[CommandArgument(0, "<FOO>")]
[Description("Dummy argument FOO")]
public int Foo { get; set; }
[CommandOption("--bar", IsHidden = true)]
[Description("You should not be able to read this unless you used the 'cli explain' command with the '--hidden' option")]
public int Bar { get; set; }
[CommandOption("--baz")]
[Description("Dummy option BAZ")]
public int Baz { get; set; }
}

View File

@ -0,0 +1,7 @@
namespace Spectre.Console.Tests.Data;
public sealed class InvalidSettings : CommandSettings
{
[CommandOption("-f|--foo [BAR]")]
public string Value { get; set; }
}

View File

@ -0,0 +1,12 @@
namespace Spectre.Console.Tests.Data;
public class LionSettings : CatSettings
{
[CommandArgument(0, "<TEETH>")]
[Description("The number of teeth the lion has.")]
public int Teeth { get; set; }
[CommandOption("-c <CHILDREN>")]
[Description("The number of children the lion has.")]
public int Children { get; set; }
}

View File

@ -0,0 +1,7 @@
namespace Spectre.Console.Tests.Data;
public class MammalSettings : AnimalSettings
{
[CommandOption("-n|-p|--name|--pet-name <VALUE>")]
public string Name { get; set; }
}

View File

@ -0,0 +1,19 @@
namespace Spectre.Console.Tests.Data;
public class MultipleArgumentVectorSettings : CommandSettings
{
[CommandArgument(0, "<Foos>")]
public string[] Foo { get; set; }
[CommandArgument(0, "<Bars>")]
public string[] Bar { get; set; }
}
public class MultipleArgumentVectorSpecifiedFirstSettings : CommandSettings
{
[CommandArgument(1, "[Bar]")]
public string Bar { get; set; }
[CommandArgument(0, "<Foos>")]
public string[] Foo { get; set; }
}

View File

@ -0,0 +1,10 @@
namespace Spectre.Console.Tests.Data;
public class OptionVectorSettings : CommandSettings
{
[CommandOption("--foo")]
public string[] Foo { get; set; }
[CommandOption("--bar")]
public int[] Bar { get; set; }
}

View File

@ -0,0 +1,35 @@
namespace Spectre.Console.Tests.Data;
public sealed class OptionalArgumentWithDefaultValueSettings : CommandSettings
{
[CommandArgument(0, "[GREETING]")]
[DefaultValue("Hello World")]
public string Greeting { get; set; }
}
public sealed class OptionalArgumentWithPropertyInitializerSettings : CommandSettings
{
[CommandArgument(0, "[NAMES]")]
public string[] Names { get; set; } = Array.Empty<string>();
[CommandOption("-c")]
public int Count { get; set; } = 1;
[CommandOption("-v")]
public int Value { get; set; } = 0;
}
public sealed class OptionalArgumentWithDefaultValueAndTypeConverterSettings : CommandSettings
{
[CommandArgument(0, "[GREETING]")]
[DefaultValue("5")]
[TypeConverter(typeof(StringToIntegerConverter))]
public int Greeting { get; set; }
}
public sealed class RequiredArgumentWithDefaultValueSettings : CommandSettings
{
[CommandArgument(0, "<GREETING>")]
[DefaultValue("Hello World")]
public string Greeting { get; set; }
}

View File

@ -0,0 +1,7 @@
namespace Spectre.Console.Tests.Data;
public sealed class StringOptionSettings : CommandSettings
{
[CommandOption("-f|--foo")]
public string Foo { get; set; }
}