-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from nblumhardt/app-update
Basic app install and app update commands
- Loading branch information
Showing
5 changed files
with
237 additions
and
1 deletion.
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,92 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Config; | ||
using SeqCli.Connection; | ||
using SeqCli.Util; | ||
using Serilog; | ||
|
||
#nullable enable | ||
|
||
namespace SeqCli.Cli.Commands.App; | ||
|
||
[Command("app", "install", "Install an app package", | ||
Example = "seqcli app install --package-id 'Seq.App.JsonArchive'")] | ||
// ReSharper disable once UnusedType.Global | ||
class InstallCommand : Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly OutputFormatFeature _output; | ||
|
||
string? _packageId, _version, _feedId; | ||
|
||
public InstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
||
Options.Add( | ||
"package-id=", | ||
"The package id of the app to install", | ||
packageId => _packageId = ArgumentString.Normalize(packageId)); | ||
|
||
Options.Add( | ||
"version=", | ||
"The package version to install; the default is to install the latest version", | ||
version => _version = ArgumentString.Normalize(version)); | ||
|
||
Options.Add( | ||
"feed-id=", | ||
"The id of the NuGet feed to install the package from; may be omitted if only one feed is configured", | ||
feedId => _feedId = ArgumentString.Normalize(feedId)); | ||
|
||
_connection = Enable<ConnectionFeature>(); | ||
_output = Enable(new OutputFormatFeature(config.Output)); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
if (_packageId == null) | ||
{ | ||
Log.Error("A `package-id` is required"); | ||
return 1; | ||
} | ||
|
||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
var feedId = _feedId; | ||
if (feedId == null) | ||
{ | ||
var feeds = await connection.Feeds.ListAsync(); | ||
if (feeds.Count != 1) | ||
{ | ||
Log.Error("A `feed-id` is required unless the server has exactly one configured feed"); | ||
return 1; | ||
} | ||
|
||
feedId = feeds.Single().Id; | ||
} | ||
|
||
var app = await connection.Apps.InstallPackageAsync(feedId, _packageId, _version); | ||
_output.WriteEntity(app); | ||
|
||
return 0; | ||
} | ||
} |
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,110 @@ | ||
// Copyright Datalust Pty Ltd and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
using SeqCli.Cli.Features; | ||
using SeqCli.Config; | ||
using SeqCli.Connection; | ||
using SeqCli.Util; | ||
using Serilog; | ||
|
||
#nullable enable | ||
|
||
namespace SeqCli.Cli.Commands.App; | ||
|
||
[Command("app", "update", "Update an installed app package", | ||
Example = "seqcli app update -n 'HTML Email'")] | ||
// ReSharper disable once UnusedType.Global | ||
class UpdateCommand : Command | ||
{ | ||
readonly SeqConnectionFactory _connectionFactory; | ||
|
||
readonly ConnectionFeature _connection; | ||
readonly OutputFormatFeature _output; | ||
|
||
string? _id, _name, _version; | ||
bool _all, _force; | ||
|
||
public UpdateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
|
||
Options.Add( | ||
"i=|id=", | ||
"The id of a single installed app to update", | ||
id => _id = ArgumentString.Normalize(id)); | ||
|
||
Options.Add( | ||
"n=|name=", | ||
"The name of the installed app to update", | ||
name => _name = ArgumentString.Normalize(name)); | ||
|
||
Options.Add( | ||
"all", | ||
"Update all installed apps; not compatible with `-i` or `-n`", | ||
_ => _all = true); | ||
|
||
Options.Add( | ||
"version=", | ||
"The package version to update to; the default is to update to the latest version in the associated feed", | ||
version => _version = ArgumentString.Normalize(version)); | ||
|
||
|
||
Options.Add( | ||
"force", | ||
"Update the app even if the target version is already installed", | ||
_ => _force = true); | ||
|
||
_connection = Enable<ConnectionFeature>(); | ||
_output = Enable(new OutputFormatFeature(config.Output)); | ||
} | ||
|
||
protected override async Task<int> Run() | ||
{ | ||
if (_all && (_id != null || _name != null) || | ||
_id != null && _name != null) | ||
{ | ||
Log.Error("The `id`, `name`, and `all` options are mutually exclusive"); | ||
return 1; | ||
} | ||
|
||
if (_all && _version != null) | ||
{ | ||
Log.Error("The `all` and `version` options are incompatible"); | ||
return 1; | ||
} | ||
|
||
if (!_all && _id == null && _name == null) | ||
{ | ||
Log.Error("One of `id`, `name`, or `all` must be specified"); | ||
return 1; | ||
} | ||
|
||
var connection = _connectionFactory.Connect(_connection); | ||
|
||
var apps = await connection.Apps.ListAsync(); | ||
foreach (var app in apps) | ||
{ | ||
if (_all || app.Id == _id || _name != null && _name.Equals(app.Name, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var updated = await connection.Apps.UpdatePackageAsync(app, _version, _force); | ||
_output.WriteEntity(updated); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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
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,25 @@ | ||
using System.Threading.Tasks; | ||
using Seq.Api; | ||
using SeqCli.EndToEnd.Support; | ||
using Serilog; | ||
using Xunit; | ||
|
||
namespace SeqCli.EndToEnd.App; | ||
|
||
// ReSharper disable once UnusedType.Global | ||
public class AppBasicsTestCase: ICliTestCase | ||
{ | ||
public Task ExecuteAsync(SeqConnection connection, ILogger logger, CliCommandRunner runner) | ||
{ | ||
var exit = runner.Exec("feed list", "-n nuget.org"); | ||
Assert.Equal(0, exit); | ||
|
||
exit = runner.Exec("app install", "--package-id Seq.App.EmailPlus"); | ||
Assert.Equal(0, exit); | ||
|
||
exit = runner.Exec("app update", "--all"); | ||
Assert.Equal(0, exit); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
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