-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
license show
command
#374
Open
gprossliner
wants to merge
5
commits into
datalust:dev
Choose a base branch
from
gprossliner:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−0
Open
license show
command
#374
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b47db6
first implementation of `license show` command
gprossliner 96e7ac8
code style
gprossliner 4a024d6
OutputWrapperLicenseEntity for usable text output
gprossliner a69afc6
edits suggested by @nblumhardt
gprossliner cd43b22
added EndToEnd test for free license
gprossliner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Seq.Api; | ||
using SeqCli.EndToEnd.Support; | ||
using Serilog; | ||
using Xunit; | ||
|
||
namespace SeqCli.EndToEnd.License; | ||
|
||
public class LicenseShowTestCase : ICliTestCase | ||
{ | ||
readonly TestDataFolder _testDataFolder; | ||
|
||
public LicenseShowTestCase(TestDataFolder testDataFolder) | ||
{ | ||
_testDataFolder = testDataFolder; | ||
} | ||
|
||
public Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner) | ||
{ | ||
|
||
// test empty text output if no license is applied | ||
runner.Exec("license show"); | ||
Assert.Equal( | ||
"", | ||
runner.LastRunProcess.Output.Trim()); | ||
|
||
// test json output if no license is applied | ||
runner.Exec("license show --json"); | ||
Assert.Contains( | ||
"You're using the free Individual license.", | ||
runner.LastRunProcess.Output.Trim()); | ||
return Task.CompletedTask; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should remove this. If there's no license applied to the server, since the output format is effectively just what's displayed in the "License text" control, returning
0
here with no output is fine. (The rest ofseqcli
follows a fairly similar set of conventions, e.g.seqcli config get -k ...
will produce no output if a setting is blank. This makes use in shell scripts easier.)