-
-
Notifications
You must be signed in to change notification settings - Fork 520
/
Copy pathDefaultCommand.cs
35 lines (29 loc) · 1.12 KB
/
DefaultCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Spectre.Console.Tests.Data;
/// <summary>
/// Represents a command that renders a custom bannder, and then help text and the application version.
/// </summary>
/// <remarks>
/// A good example of the behaviour that some spectre.console users would like from their application default command.
/// </remarks>
public sealed class DefaultCommand : Command<EmptyCommandSettings>
{
private readonly IAnsiConsole _console;
public DefaultCommand(IAnsiConsole console)
{
_console = console;
}
public override int Execute(CommandContext context, EmptyCommandSettings settings)
{
// Fancy application banner.
_console.WriteLine("----------------------------------");
_console.WriteLine("--- DEFAULT COMMAND ---");
_console.WriteLine("----------------------------------");
_console.WriteLine();
// Command help.
_console.SafeRender(context.Help);
_console.WriteLine();
// Application version.
_console.MarkupLine("Version {0}", context.ApplicationVersion);
return 0;
}
}