Skip to content

Commit 4d173ef

Browse files
committed
Merge branch 'gprossliner-dev' into dev
2 parents 9d09f53 + a99ac41 commit 4d173ef

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 (_output.Json)
38+
{
39+
_output.WriteEntity(license);
40+
}
41+
else
42+
{
43+
_output.WriteText(license?.LicenseText);
44+
}
45+
46+
return 0;
47+
}
48+
}

src/SeqCli/Cli/Features/OutputFormatFeature.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,10 @@ public void ListEntities(IEnumerable<Entity> list)
185185
WriteEntity(entity);
186186
}
187187
}
188-
}
188+
189+
// ReSharper disable once MemberCanBeMadeStatic.Global
190+
public void WriteText(string? text)
191+
{
192+
Console.WriteLine(text?.TrimEnd());
193+
}
194+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Threading.Tasks;
2+
using Seq.Api;
3+
using SeqCli.EndToEnd.Support;
4+
using Serilog;
5+
using Xunit;
6+
7+
namespace SeqCli.EndToEnd.License;
8+
9+
public class LicenseShowTestCase : ICliTestCase
10+
{
11+
public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
12+
{
13+
var license = await connection.Licenses.FindCurrentAsync();
14+
Assert.True(license.IsSingleUser);
15+
16+
runner.Exec("license show");
17+
Assert.Equal(
18+
"",
19+
runner.LastRunProcess!.Output.Trim());
20+
21+
runner.Exec("license show --json");
22+
Assert.Contains(
23+
"You're using the free Individual license.",
24+
runner.LastRunProcess!.Output.Trim());
25+
}
26+
}

0 commit comments

Comments
 (0)