mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Move Spectre.Console.Cli to it's own package
This commit is contained in:

committed by
Patrik Svensson

parent
b600832e00
commit
36ca22ffac
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user