Skip to content

Commit 254221a

Browse files
committed
Merge branch 'dev' of https://github.com/gprossliner/seqcli into gprossliner-dev
2 parents 9d09f53 + cd43b22 commit 254221a

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using Seq.Api.Model;
6+
using Seq.Api.Model.License;
7+
using SeqCli.Cli.Features;
8+
using SeqCli.Config;
9+
using SeqCli.Connection;
10+
using SeqCli.Util;
11+
using Serilog;
12+
13+
// ReSharper disable once UnusedType.Global
14+
15+
namespace SeqCli.Cli.Commands.License;
16+
17+
[Command("license", "show", "Shows license applied to the Seq server",
18+
Example = "seqcli license show")]
19+
class ShowCommand : Command
20+
{
21+
readonly SeqConnectionFactory _connectionFactory;
22+
readonly ConnectionFeature _connection;
23+
readonly OutputFormatFeature _output;
24+
25+
public ShowCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
26+
{
27+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
28+
_connection = Enable<ConnectionFeature>();
29+
_output = Enable(new OutputFormatFeature(config.Output));
30+
}
31+
32+
protected override async Task<int> Run()
33+
{
34+
var connection = _connectionFactory.Connect(_connection);
35+
var license = await connection.Licenses.FindCurrentAsync();
36+
37+
if (license == null)
38+
{
39+
Log.Warning("No license is currently applied to the server.");
40+
return 2;
41+
}
42+
43+
_output.WriteEntity(_output.Json ? license : new OutputWrapperLicenseEntity(license));
44+
45+
return 0;
46+
}
47+
48+
/// <summary>
49+
/// Wraps the license entity for none json output.
50+
/// </summary>
51+
class OutputWrapperLicenseEntity : Entity
52+
{
53+
public OutputWrapperLicenseEntity(LicenseEntity license)
54+
{
55+
this.Id = license.LicenseText;
56+
}
57+
}
58+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using Seq.Api;
5+
using SeqCli.EndToEnd.Support;
6+
using Serilog;
7+
using Xunit;
8+
9+
namespace SeqCli.EndToEnd.License;
10+
11+
public class LicenseShowTestCase : ICliTestCase
12+
{
13+
readonly TestDataFolder _testDataFolder;
14+
15+
public LicenseShowTestCase(TestDataFolder testDataFolder)
16+
{
17+
_testDataFolder = testDataFolder;
18+
}
19+
20+
public Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
21+
{
22+
23+
// test empty text output if no license is applied
24+
runner.Exec("license show");
25+
Assert.Equal(
26+
"",
27+
runner.LastRunProcess.Output.Trim());
28+
29+
// test json output if no license is applied
30+
runner.Exec("license show --json");
31+
Assert.Contains(
32+
"You're using the free Individual license.",
33+
runner.LastRunProcess.Output.Trim());
34+
return Task.CompletedTask;
35+
}
36+
}

0 commit comments

Comments
 (0)