-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathShowCommand.cs
58 lines (49 loc) · 1.62 KB
/
ShowCommand.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Seq.Api.Model;
using Seq.Api.Model.License;
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Connection;
using SeqCli.Util;
using Serilog;
// ReSharper disable once UnusedType.Global
namespace SeqCli.Cli.Commands.License;
[Command("license", "show", "Shows license applied to the Seq server",
Example = "seqcli license show")]
class ShowCommand : Command
{
readonly SeqConnectionFactory _connectionFactory;
readonly ConnectionFeature _connection;
readonly OutputFormatFeature _output;
public ShowCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
_connection = Enable<ConnectionFeature>();
_output = Enable(new OutputFormatFeature(config.Output));
}
protected override async Task<int> Run()
{
var connection = _connectionFactory.Connect(_connection);
var license = await connection.Licenses.FindCurrentAsync();
if (license == null)
{
Log.Warning("No license is currently applied to the server.");
return 2;
}
_output.WriteEntity(_output.Json ? license : new OutputWrapperLicenseEntity(license));
return 0;
}
/// <summary>
/// Wraps the license entity for none json output.
/// </summary>
class OutputWrapperLicenseEntity : Entity
{
public OutputWrapperLicenseEntity(LicenseEntity license)
{
this.Id = license.LicenseText;
}
}
}