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}
0 commit comments