Skip to content

Commit a60edea

Browse files
committed
Merge branch 'dev' of https://github.com/datalust/seqcli into feature/forwarder
2 parents bc82148 + 4d173ef commit a60edea

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 ConnectionFeature _connection;
22+
readonly OutputFormatFeature _output;
23+
readonly StoragePathFeature _storage;
24+
25+
public ShowCommand()
26+
{
27+
_connection = Enable<ConnectionFeature>();
28+
_output = Enable<OutputFormatFeature>();
29+
_storage = Enable<StoragePathFeature>();
30+
}
31+
32+
protected override async Task<int> Run()
33+
{
34+
var config = RuntimeConfigurationLoader.Load(_storage);
35+
var output = _output.GetOutputFormat(config);
36+
37+
var connection = SeqConnectionFactory.Connect(_connection, config);
38+
var license = await connection.Licenses.FindCurrentAsync();
39+
40+
if (output.Json)
41+
{
42+
output.WriteEntity(license);
43+
}
44+
else
45+
{
46+
output.WriteText(license?.LicenseText);
47+
}
48+
49+
return 0;
50+
}
51+
}

src/SeqCli/Cli/Features/OutputFormat.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,12 @@ public void ListEntities(IEnumerable<Entity> list)
165165
WriteEntity(entity);
166166
}
167167
}
168-
}
168+
169+
// ReSharper disable once MemberCanBeMadeStatic.Global
170+
#pragma warning disable CA1822
171+
public void WriteText(string? text)
172+
#pragma warning restore CA1822
173+
{
174+
Console.WriteLine(text?.TrimEnd());
175+
}
176+
}

src/SeqCli/Cli/Features/OutputFormatFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ public override void Enable(OptionSet options)
3939
"Force redirected output to have ANSI color (unless `--no-color` is also specified)",
4040
_ => _forceColor = true);
4141
}
42-
}
42+
}
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)