Skip to content

Commit 1e0bb81

Browse files
committed
Flesh out the added commands
1 parent 1c1749b commit 1e0bb81

File tree

13 files changed

+117
-61
lines changed

13 files changed

+117
-61
lines changed

src/SeqCli/Cli/Commands/ApiKey/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ protected override async Task<int> Run()
4747
var list = _entityIdentity.Id != null ?
4848
new[] { await connection.ApiKeys.FindAsync(_entityIdentity.Id) } :
4949
(await connection.ApiKeys.ListAsync())
50-
.Where(ak => _entityIdentity.Title == null || _entityIdentity.Title == ak.Title)
51-
.ToArray();
50+
.Where(ak => _entityIdentity.Title == null || _entityIdentity.Title == ak.Title);
5251

53-
foreach (var apiKey in list)
54-
{
55-
_output.WriteEntity(apiKey);
56-
}
52+
_output.ListEntities(list);
5753

5854
return 0;
5955
}

src/SeqCli/Cli/Commands/App/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ protected override async Task<int> Run()
5151
var list = Id != null ?
5252
new[] { await connection.Apps.FindAsync(Id) } :
5353
(await connection.Apps.ListAsync())
54-
.Where(ak => PackageId == null || PackageId == ak.Name)
55-
.ToArray();
54+
.Where(ak => PackageId == null || PackageId == ak.Package.PackageId);
5655

57-
foreach (var app in list)
58-
{
59-
_output.WriteEntity(app);
60-
}
56+
_output.ListEntities(list);
6157

6258
return 0;
6359
}

src/SeqCli/Cli/Commands/AppInstance/CreateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace SeqCli.Cli.Commands.AppInstance;
1313

14-
[Command("appinstance", "create", "Create a signal",
14+
[Command("appinstance", "create", "Create an instance of an installed app",
1515
Example = "seqcli appinstance create -t 'Email Ops' --app hostedapp-314159 -p [email protected]")]
1616
class CreateCommand : Command
1717
{
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
1-
namespace SeqCli.Cli.Commands.AppInstance;
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using SeqCli.Cli.Features;
5+
using SeqCli.Config;
6+
using SeqCli.Connection;
27

3-
public class ListCommand
8+
namespace SeqCli.Cli.Commands.AppInstance;
9+
10+
[Command("appinstance", "list", "List instances of installed apps", Example="seqcli appinstance list")]
11+
class ListCommand : Command
412
{
13+
readonly SeqConnectionFactory _connectionFactory;
14+
15+
readonly EntityIdentityFeature _entityIdentity;
16+
readonly ConnectionFeature _connection;
17+
readonly OutputFormatFeature _output;
18+
19+
public ListCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
20+
{
21+
if (config == null) throw new ArgumentNullException(nameof(config));
22+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
23+
24+
_entityIdentity = Enable(new EntityIdentityFeature("app instance", "list"));
25+
_output = Enable(new OutputFormatFeature(config.Output));
26+
_connection = Enable<ConnectionFeature>();
27+
}
528

29+
protected override async Task<int> Run()
30+
{
31+
var connection = _connectionFactory.Connect(_connection);
32+
33+
var list = _entityIdentity.Id != null ?
34+
new[] { await connection.AppInstances.FindAsync(_entityIdentity.Id) } :
35+
(await connection.AppInstances.ListAsync())
36+
.Where(d => _entityIdentity.Title == null || _entityIdentity.Title == d.Title);
37+
38+
_output.ListEntities(list);
39+
40+
return 0;
41+
}
642
}
Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
1-
namespace SeqCli.Cli.Commands.AppInstance;
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using SeqCli.Cli.Features;
5+
using SeqCli.Connection;
6+
using Serilog;
27

3-
public class RemoveCommand
8+
namespace SeqCli.Cli.Commands.AppInstance;
9+
[Command("appinstance", "remove", "Remove an app instance from the server",
10+
Example="seqcli appinstance remove -t 'Email Ops'")]
11+
12+
class RemoveCommand : Command
413
{
5-
14+
readonly SeqConnectionFactory _connectionFactory;
15+
16+
readonly EntityIdentityFeature _entityIdentity;
17+
readonly ConnectionFeature _connection;
18+
19+
public RemoveCommand(SeqConnectionFactory connectionFactory)
20+
{
21+
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
22+
23+
_entityIdentity = Enable(new EntityIdentityFeature("app instance", "remove"));
24+
_connection = Enable<ConnectionFeature>();
25+
}
26+
27+
protected override async Task<int> Run()
28+
{
29+
if (_entityIdentity.Title == null && _entityIdentity.Id == null)
30+
{
31+
Log.Error("A `title` or `id` must be specified");
32+
return 1;
33+
}
34+
35+
var connection = _connectionFactory.Connect(_connection);
36+
37+
var toRemove = _entityIdentity.Id != null ?
38+
new[] {await connection.AppInstances.FindAsync(_entityIdentity.Id)} :
39+
(await connection.AppInstances.ListAsync())
40+
.Where(ak => _entityIdentity.Title == ak.Title)
41+
.ToArray();
42+
43+
if (!toRemove.Any())
44+
{
45+
Log.Error("No matching app instance was found");
46+
return 1;
47+
}
48+
49+
foreach (var appInstanceEntity in toRemove)
50+
await connection.AppInstances.RemoveAsync(appInstanceEntity);
51+
52+
return 0;
53+
}
654
}

src/SeqCli/Cli/Commands/Dashboard/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ protected override async Task<int> Run()
4949
var list = _entityIdentity.Id != null ?
5050
new[] { await connection.Dashboards.FindAsync(_entityIdentity.Id) } :
5151
(await connection.Dashboards.ListAsync(ownerId: _entityOwner.OwnerId, shared: _entityOwner.IncludeShared))
52-
.Where(d => _entityIdentity.Title == null || _entityIdentity.Title == d.Title)
53-
.ToArray();
52+
.Where(d => _entityIdentity.Title == null || _entityIdentity.Title == d.Title);
5453

55-
foreach (var dashboardEntity in list)
56-
{
57-
_output.WriteEntity(dashboardEntity);
58-
}
54+
_output.ListEntities(list);
5955

6056
return 0;
6157
}

src/SeqCli/Cli/Commands/Feed/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ protected override async Task<int> Run()
5757
var list = _id != null ?
5858
new[] { await connection.Feeds.FindAsync(_id) } :
5959
(await connection.Feeds.ListAsync())
60-
.Where(f => _name == null || _name == f.Name)
61-
.ToArray();
60+
.Where(f => _name == null || _name == f.Name);
6261

63-
foreach (var feed in list)
64-
{
65-
_output.WriteEntity(feed);
66-
}
62+
_output.ListEntities(list);
6763

6864
return 0;
6965
}

src/SeqCli/Cli/Commands/Node/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,9 @@ protected override async Task<int> Run()
5959
var list = _id != null ?
6060
new[] { await connection.ClusterNodes.FindAsync(_id) } :
6161
(await connection.ClusterNodes.ListAsync())
62-
.Where(n => _name == null || _name == n.Name)
63-
.ToArray();
62+
.Where(n => _name == null || _name == n.Name);
6463

65-
foreach (var clusterNode in list)
66-
{
67-
_output.WriteEntity(clusterNode);
68-
}
64+
_output.ListEntities(list);
6965

7066
return 0;
7167
}

src/SeqCli/Cli/Commands/RetentionPolicy/ListCommand.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ protected override async Task<int> Run()
5454
(await connection.RetentionPolicies.ListAsync())
5555
.ToArray();
5656

57-
foreach (var policy in list)
58-
{
59-
if (_output.Json)
60-
_output.WriteEntity(policy);
61-
else
62-
Console.WriteLine(policy.Id);
63-
}
57+
_output.ListEntities(list);
6458

6559
return 0;
6660
}

src/SeqCli/Cli/Commands/Signal/ListCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ protected override async Task<int> Run()
4949
var list = _entityIdentity.Id != null ?
5050
new[] { await connection.Signals.FindAsync(_entityIdentity.Id) } :
5151
(await connection.Signals.ListAsync(ownerId: _entityOwner.OwnerId, shared: _entityOwner.IncludeShared))
52-
.Where(signal => _entityIdentity.Title == null || _entityIdentity.Title == signal.Title)
53-
.ToArray();
52+
.Where(signal => _entityIdentity.Title == null || _entityIdentity.Title == signal.Title);
5453

55-
foreach (var signal in list)
56-
{
57-
_output.WriteEntity(signal);
58-
}
54+
_output.ListEntities(list);
5955

6056
return 0;
6157
}

0 commit comments

Comments
 (0)