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

@ -1,25 +0,0 @@
namespace Spectre.Console.Cli;
public static class CommandContextExtensions
{
public static void ShouldHaveRemainingArgument(this CommandContext context, string name, string[] values)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
context.Remaining.Parsed.Contains(name).ShouldBeTrue();
context.Remaining.Parsed[name].Count().ShouldBe(values.Length);
foreach (var value in values)
{
context.Remaining.Parsed[name].ShouldContain(value);
}
}
}

View File

@ -1,16 +0,0 @@
namespace Spectre.Console;
public static class ShouldlyExtensions
{
[DebuggerStepThrough]
public static T And<T>(this T item, Action<T> action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
action(item);
return item;
}
}

View File

@ -1,52 +0,0 @@
namespace Spectre.Console.Testing;
public sealed class FakeTypeRegistrar : ITypeRegistrar
{
public Dictionary<Type, List<Type>> Registrations { get; }
public Dictionary<Type, List<object>> Instances { get; }
public Func<Dictionary<Type, List<Type>>, Dictionary<Type, List<object>>, ITypeResolver> TypeResolverFactory { get; set; }
public FakeTypeRegistrar()
{
Registrations = new Dictionary<Type, List<Type>>();
Instances = new Dictionary<Type, List<object>>();
}
public void Register(Type service, Type implementation)
{
if (!Registrations.ContainsKey(service))
{
Registrations.Add(service, new List<Type> { implementation });
}
else
{
Registrations[service].Add(implementation);
}
}
public void RegisterInstance(Type service, object implementation)
{
if (!Instances.ContainsKey(service))
{
Instances.Add(service, new List<object> { implementation });
}
}
public void RegisterLazy(Type service, Func<object> factory)
{
if (factory is null)
{
throw new ArgumentNullException(nameof(factory));
}
if (!Instances.ContainsKey(service))
{
Instances.Add(service, new List<object> { factory() });
}
}
public ITypeResolver Build()
{
return TypeResolverFactory?.Invoke(Registrations, Instances);
}
}

View File

@ -1,35 +0,0 @@
namespace Spectre.Console.Testing;
public sealed class FakeTypeResolver : ITypeResolver
{
private readonly Dictionary<Type, List<Type>> _registrations;
private readonly Dictionary<Type, List<object>> _instances;
public FakeTypeResolver(
Dictionary<Type, List<Type>> registrations,
Dictionary<Type, List<object>> instances)
{
_registrations = registrations ?? throw new ArgumentNullException(nameof(registrations));
_instances = instances ?? throw new ArgumentNullException(nameof(instances));
}
public static Func<Dictionary<Type, List<Type>>, Dictionary<Type, List<object>>, ITypeResolver> Factory =>
(r, i) => new FakeTypeResolver(r, i);
public object Resolve(Type type)
{
if (_instances.TryGetValue(type, out var instances))
{
return instances.FirstOrDefault();
}
if (_registrations.TryGetValue(type, out var registrations))
{
return registrations.Count == 0
? null
: Activator.CreateInstance(type);
}
return null;
}
}

View File

@ -1,12 +0,0 @@
namespace Spectre.Console.Tests;
[AttributeUsage(AttributeTargets.Method)]
public sealed class GitHubIssueAttribute : Attribute
{
public int IssueId { get; }
public GitHubIssueAttribute(int issueId)
{
IssueId = issueId;
}
}