forked from datalust/seqcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateCommand.cs
More file actions
108 lines (91 loc) · 3.42 KB
/
UpdateCommand.cs
File metadata and controls
108 lines (91 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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.Api;
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Util;
using Serilog;
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 ConnectionFeature _connection;
readonly OutputFormatFeature _output;
readonly StoragePathFeature _storagePath;
string? _id, _name, _version;
bool _all, _force;
public UpdateCommand()
{
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<OutputFormatFeature>();
_storagePath = Enable<StoragePathFeature>();
}
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 config = RuntimeConfigurationLoader.Load(_storagePath);
var connection = SeqConnectionFactory.Connect(_connection, config);
var output = _output.GetOutputFormat(config);
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;
}
}