Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Task("Test")
NoBuild = true,
});

DotNetTest("./test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj", new DotNetTestSettings {
Configuration = configuration,
NoRestore = true,
NoBuild = true,
});

DotNetTest("./test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj", new DotNetTestSettings {
Configuration = configuration,
NoRestore = true,
Expand Down
2 changes: 1 addition & 1 deletion dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "2.1.0",
"version": "2.2.0",
"commands": [
"dotnet-cake"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/Cli/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\..\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.ImageSharp"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Paths", "Console\Paths\Paths.csproj", "{65CB00B0-A3AE-4E8F-A990-4C8C1A232FE2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.Cli", "..\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj", "{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -493,6 +495,18 @@ Global
{65CB00B0-A3AE-4E8F-A990-4C8C1A232FE2}.Release|x64.Build.0 = Release|Any CPU
{65CB00B0-A3AE-4E8F-A990-4C8C1A232FE2}.Release|x86.ActiveCfg = Release|Any CPU
{65CB00B0-A3AE-4E8F-A990-4C8C1A232FE2}.Release|x86.Build.0 = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|x64.ActiveCfg = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|x64.Build.0 = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|x86.ActiveCfg = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Debug|x86.Build.0 = Debug|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|Any CPU.Build.0 = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|x64.ActiveCfg = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|x64.Build.0 = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|x86.ActiveCfg = Release|Any CPU
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -506,6 +520,7 @@ Global
{DD8EC1B0-F50C-44E4-8399-2D560F95E572} = {2571F1BD-6556-4F96-B27B-B6190E1BF13A}
{0C58FB17-F60A-47AB-84BF-961EC8C06AE6} = {2571F1BD-6556-4F96-B27B-B6190E1BF13A}
{A127CE7D-A5A7-4745-9809-EBD7CB12CEE7} = {2571F1BD-6556-4F96-B27B-B6190E1BF13A}
{EFAADF6A-C77D-41EC-83F5-BBB4FFC5A6D7} = {2571F1BD-6556-4F96-B27B-B6190E1BF13A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3EE724C5-CAB4-410D-AC63-8D4260EF83ED}
Expand Down
1 change: 1 addition & 0 deletions examples/Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Spectre.Console.Cli\Spectre.Console.Cli.csproj" />
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions src/Spectre.Console.Cli/Properties/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global using System;
global using System.Collections;
global using System.Collections.Generic;
global using System.ComponentModel;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.IO;
global using System.Linq;
global using System.Reflection;
global using System.Text;
global using System.Threading.Tasks;
global using System.Xml;
global using Spectre.Console.Cli.Unsafe;
global using Spectre.Console.Rendering;
34 changes: 34 additions & 0 deletions src/Spectre.Console.Cli/Spectre.Console.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<NoWarn>SA1633</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
<None Include="../../resources/gfx/small-logo.png" Pack="true" PackagePath="\" Link="Properties/small-logo.png" />
<InternalsVisibleTo Include="Spectre.Console.Cli.Tests" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.160" PrivateAssets="all" />
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[$(AnnotatedReferenceAssemblyVersion)]" />
<PackageReference Include="Nullable" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<AnnotatedReferenceAssemblyVersion>3.0.0</AnnotatedReferenceAssemblyVersion>
<GenerateNullableAttributes>False</GenerateNullableAttributes>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Spectre.Console;

public static class ShouldlyExtensions
internal static class ShouldlyExtensions
{
[DebuggerStepThrough]
public static T And<T>(this T item, Action<T> action)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
namespace Spectre.Console.Testing;

/// <summary>
/// A fake type registrar suitable for testing.
/// </summary>
public sealed class FakeTypeRegistrar : ITypeRegistrar
{
/// <summary>
/// Gets all registrations.
/// </summary>
public Dictionary<Type, List<Type>> Registrations { get; }

/// <summary>
/// Gets all singleton registrations.
/// </summary>
public Dictionary<Type, List<object>> Instances { get; }
public Func<Dictionary<Type, List<Type>>, Dictionary<Type, List<object>>, ITypeResolver> TypeResolverFactory { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="FakeTypeRegistrar"/> class.
/// </summary>
public FakeTypeRegistrar()
{
Registrations = new Dictionary<Type, List<Type>>();
Instances = new Dictionary<Type, List<object>>();
}

/// <inheritdoc/>
public void Register(Type service, Type implementation)
{
if (!Registrations.ContainsKey(service))
Expand All @@ -24,6 +37,7 @@ public void Register(Type service, Type implementation)
}
}

/// <inheritdoc/>
public void RegisterInstance(Type service, object implementation)
{
if (!Instances.ContainsKey(service))
Expand All @@ -32,6 +46,7 @@ public void RegisterInstance(Type service, object implementation)
}
}

/// <inheritdoc/>
public void RegisterLazy(Type service, Func<object> factory)
{
if (factory is null)
Expand All @@ -45,8 +60,9 @@ public void RegisterLazy(Type service, Func<object> factory)
}
}

/// <inheritdoc/>
public ITypeResolver Build()
{
return TypeResolverFactory?.Invoke(Registrations, Instances);
return new FakeTypeResolver(Registrations, Instances);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
namespace Spectre.Console.Testing;

/// <summary>
/// A fake type resolver suitable for testing.
/// </summary>
public sealed class FakeTypeResolver : ITypeResolver
{
private readonly Dictionary<Type, List<Type>> _registrations;
private readonly Dictionary<Type, List<object>> _instances;

/// <summary>
/// Initializes a new instance of the <see cref="FakeTypeResolver"/> class.
/// </summary>
/// <param name="registrations">The registrations.</param>
/// <param name="instances">The singleton registrations.</param>
public FakeTypeResolver(
Dictionary<Type, List<Type>> registrations,
Dictionary<Type, List<object>> instances)
Expand All @@ -13,11 +21,14 @@ public FakeTypeResolver(
_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)
/// <inheritdoc/>
public object? Resolve(Type? type)
{
if (type == null)
{
return null;
}

if (_instances.TryGetValue(type, out var instances))
{
return instances.FirstOrDefault();
Expand Down
2 changes: 2 additions & 0 deletions src/Spectre.Console.Testing/Properties/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
global using System;
global using System.Collections.Generic;
global using System.Diagnostics;
global using System.IO;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using Spectre.Console.Cli;
Expand Down
6 changes: 6 additions & 0 deletions src/Spectre.Console.Testing/Spectre.Console.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
<Description>Contains testing utilities for Spectre.Console.</Description>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Spectre.Console.Tests" />
<InternalsVisibleTo Include="Spectre.Console.Cli.Tests" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
<None Include="../../resources/gfx/small-logo.png" Pack="true" PackagePath="\" Link="Properties/small-logo.png" />
</ItemGroup>

<ItemGroup Label="Project References">
<ProjectReference Include="..\Spectre.Console.Cli\Spectre.Console.Cli.csproj" />
<ProjectReference Include="..\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>

Expand Down
32 changes: 30 additions & 2 deletions src/Spectre.Console.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console", "Spectre.Console\Spectre.Console.csproj", "{80DCBEF3-99D6-46C0-9C5B-42B4534D9113}"
EndProject
Expand Down Expand Up @@ -30,6 +30,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{E0E4
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.Tests", "..\test\Spectre.Console.Tests\Spectre.Console.Tests.csproj", "{60A4CADD-2B3D-48ED-89C0-1637A1F111AE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.Cli", "Spectre.Console.Cli\Spectre.Console.Cli.csproj", "{1B67B74F-1243-4381-9A2B-86EA66D135C5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spectre.Console.Cli.Tests", "..\test\Spectre.Console.Cli.Tests\Spectre.Console.Cli.Tests.csproj", "{E07C46D2-714F-4116-BADD-FEE09617A9C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -88,6 +92,30 @@ Global
{60A4CADD-2B3D-48ED-89C0-1637A1F111AE}.Release|x64.Build.0 = Release|Any CPU
{60A4CADD-2B3D-48ED-89C0-1637A1F111AE}.Release|x86.ActiveCfg = Release|Any CPU
{60A4CADD-2B3D-48ED-89C0-1637A1F111AE}.Release|x86.Build.0 = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|x64.ActiveCfg = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|x64.Build.0 = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|x86.ActiveCfg = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Debug|x86.Build.0 = Debug|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|Any CPU.Build.0 = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|x64.ActiveCfg = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|x64.Build.0 = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|x86.ActiveCfg = Release|Any CPU
{1B67B74F-1243-4381-9A2B-86EA66D135C5}.Release|x86.Build.0 = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|x64.ActiveCfg = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|x64.Build.0 = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|x86.ActiveCfg = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Debug|x86.Build.0 = Debug|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|Any CPU.Build.0 = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|x64.ActiveCfg = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|x64.Build.0 = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|x86.ActiveCfg = Release|Any CPU
{E07C46D2-714F-4116-BADD-FEE09617A9C4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 0 additions & 1 deletion src/Spectre.Console/Properties/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
global using System.Threading;
global using System.Threading.Tasks;
global using System.Xml;
global using Spectre.Console.Cli.Unsafe;
global using Spectre.Console.Enrichment;
global using Spectre.Console.Internal;
global using Spectre.Console.Rendering;
Expand Down
1 change: 0 additions & 1 deletion src/Spectre.Console/Spectre.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<EmbeddedResource Include="Widgets\Figlet\Fonts\Standard.flf" />
<None Remove="Widgets\Figlet\Fonts\Standard.flf" />
<None Include="../../resources/gfx/small-logo.png" Pack="true" PackagePath="\" Link="Properties/small-logo.png" />
<None Include="..\.editorconfig" Link="Cli\.editorconfig" />
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public DumpRemainingCommand(IAnsiConsole console)
_console = console;
}

public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings)
public override int Execute(CommandContext context, EmptyCommandSettings settings)
{
if (context.Remaining.Raw.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public sealed class NoDescriptionCommand : Command<EmptyCommandSettings>
[CommandOption("-f|--foo <VALUE>")]
public int Foo { get; set; }

public override int Execute([NotNull] CommandContext context, [NotNull] EmptyCommandSettings settings)
public override int Execute(CommandContext context, EmptyCommandSettings settings)
{
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Arguments can not contain options.

--foo <BAR>
^^^^^ Not permitted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Encountered invalid character '$' in option name.

--f$oo
^ Invalid character
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Encountered invalid character '$' in value name.

-f|--foo <F$OO>
^ Invalid character
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Long option names must consist of more than one character.

--f
^ Invalid option name
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
No long or short name for option has been specified.

<FOO>
^^^^^ Missing option. Was this meant to be an argument?
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Multiple option values are not supported.

-f|--foo <FOO> <BAR>
^^^^^ Too many option values
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: An error occured when parsing template.
Multiple values are not supported.

<FOO> <BAR>
^^^^^ Too many values
Loading