Skip to content

Commit a99ac41

Browse files
committed
Update output for empty licenses
1 parent 254221a commit a99ac41

File tree

3 files changed

+21
-35
lines changed

3 files changed

+21
-35
lines changed

src/SeqCli/Cli/Commands/License/ShowCommand.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,15 @@ protected override async Task<int> Run()
3434
var connection = _connectionFactory.Connect(_connection);
3535
var license = await connection.Licenses.FindCurrentAsync();
3636

37-
if (license == null)
37+
if (_output.Json)
3838
{
39-
Log.Warning("No license is currently applied to the server.");
40-
return 2;
39+
_output.WriteEntity(license);
4140
}
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)
41+
else
5442
{
55-
this.Id = license.LicenseText;
43+
_output.WriteText(license?.LicenseText);
5644
}
45+
46+
return 0;
5747
}
58-
}
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: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
42
using Seq.Api;
53
using SeqCli.EndToEnd.Support;
64
using Serilog;
@@ -10,27 +8,19 @@ namespace SeqCli.EndToEnd.License;
108

119
public class LicenseShowTestCase : ICliTestCase
1210
{
13-
readonly TestDataFolder _testDataFolder;
14-
15-
public LicenseShowTestCase(TestDataFolder testDataFolder)
11+
public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner)
1612
{
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
13+
var license = await connection.Licenses.FindCurrentAsync();
14+
Assert.True(license.IsSingleUser);
15+
2416
runner.Exec("license show");
2517
Assert.Equal(
2618
"",
27-
runner.LastRunProcess.Output.Trim());
19+
runner.LastRunProcess!.Output.Trim());
2820

29-
// test json output if no license is applied
3021
runner.Exec("license show --json");
3122
Assert.Contains(
3223
"You're using the free Individual license.",
33-
runner.LastRunProcess.Output.Trim());
34-
return Task.CompletedTask;
24+
runner.LastRunProcess!.Output.Trim());
3525
}
3626
}

0 commit comments

Comments
 (0)