mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 13:48:16 +08:00
Add Spectre.Cli to Spectre.Console
* Renames Spectre.Cli to Spectre.Console.Cli. * Now uses Verify with Spectre.Console.Cli tests. * Removes some duplicate definitions. Closes #168
This commit is contained in:

committed by
Patrik Svensson

parent
0bbf9b81a9
commit
0ae419326d
49
src/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs
Normal file
49
src/Spectre.Console.Tests/Data/Commands/AnimalCommand.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Spectre.Console.Cli;
|
||||
using SystemConsole = System.Console;
|
||||
|
||||
namespace Spectre.Console.Tests.Data
|
||||
{
|
||||
public abstract class AnimalCommand<TSettings> : Command<TSettings>
|
||||
where TSettings : CommandSettings
|
||||
{
|
||||
protected void DumpSettings(CommandContext context, TSettings settings)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings));
|
||||
}
|
||||
|
||||
var properties = settings.GetType().GetProperties();
|
||||
foreach (var group in properties.GroupBy(x => x.DeclaringType).Reverse())
|
||||
{
|
||||
SystemConsole.WriteLine();
|
||||
SystemConsole.ForegroundColor = ConsoleColor.Yellow;
|
||||
SystemConsole.WriteLine(group.Key.FullName);
|
||||
SystemConsole.ResetColor();
|
||||
|
||||
foreach (var property in group)
|
||||
{
|
||||
SystemConsole.WriteLine($" {property.Name} = {property.GetValue(settings)}");
|
||||
}
|
||||
}
|
||||
|
||||
if (context.Remaining.Raw.Count > 0)
|
||||
{
|
||||
SystemConsole.WriteLine();
|
||||
SystemConsole.ForegroundColor = ConsoleColor.Yellow;
|
||||
SystemConsole.WriteLine("Remaining:");
|
||||
SystemConsole.ResetColor();
|
||||
SystemConsole.WriteLine(string.Join(", ", context.Remaining));
|
||||
}
|
||||
|
||||
SystemConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user