1
1
using System ;
2
2
using System . Management . Automation ;
3
- using Eryph . ClientRuntime ;
4
3
using Eryph . ComputeClient . Models ;
5
4
using JetBrains . Annotations ;
6
5
7
- namespace Eryph . ComputeClient . Commands . Projects
6
+ namespace Eryph . ComputeClient . Commands . Projects ;
7
+
8
+ [ PublicAPI ]
9
+ [ Cmdlet ( VerbsCommon . Remove , "EryphProject" ) ]
10
+ [ OutputType ( typeof ( Operation ) ) ]
11
+ public class RemoveProjectCommand : ProjectCmdlet
8
12
{
9
- [ PublicAPI ]
10
- [ Cmdlet ( VerbsCommon . Remove , "EryphProject" ) ]
11
- [ OutputType ( typeof ( Operation ) ) ]
12
- public class RemoveProjectCommand : ProjectCmdlet
13
- {
14
- [ Parameter (
15
- Position = 0 ,
16
- ValueFromPipeline = true ,
17
- Mandatory = true ,
18
- ValueFromPipelineByPropertyName = true ) ]
19
- public string [ ] Id { get ; set ; }
20
-
21
- [ Parameter ]
22
- public SwitchParameter NoWait
23
- {
24
- get => _nowait ;
25
- set => _nowait = value ;
26
- }
13
+ [ Parameter (
14
+ Position = 0 ,
15
+ ValueFromPipeline = true ,
16
+ Mandatory = true ,
17
+ ValueFromPipelineByPropertyName = true ) ]
18
+ public string [ ] Id { get ; set ; }
19
+
20
+ [ Parameter ]
21
+ public SwitchParameter Force { get ; set ; }
27
22
28
- private bool _nowait ;
23
+ [ Parameter ]
24
+ public SwitchParameter NoWait { get ; set ; }
29
25
26
+ private bool _yesToAll ;
27
+ private bool _noToAll ;
30
28
31
- protected override void ProcessRecord ( )
29
+ protected override void ProcessRecord ( )
30
+ {
31
+ foreach ( var id in Id )
32
32
{
33
- foreach ( var id in Id )
33
+ Project project ;
34
+ try
34
35
{
35
- WaitForProject ( Factory . CreateProjectsClient ( ) . Delete ( id )
36
- , _nowait , false , id ) ;
36
+ project = Factory . CreateProjectsClient ( ) . Get ( id ) ;
37
+ }
38
+ catch ( Exception ex )
39
+ {
40
+ WriteError ( new ErrorRecord ( ex , "ProjectNotFound" , ErrorCategory . ObjectNotFound , id ) ) ;
41
+ continue ;
37
42
}
38
43
39
- }
44
+ if ( ! Force && ! ShouldContinue ( $ "Project '{ project . Name } ' (Id:{ id } ) and all catlets in the project will be deleted!", "Warning!" ,
45
+ ref _yesToAll , ref _noToAll ) )
46
+ {
47
+ continue ;
48
+ }
40
49
50
+ WaitForProject ( Factory . CreateProjectsClient ( ) . Delete ( id ) , NoWait , false , id ) ;
51
+ }
41
52
}
42
- }
53
+ }
0 commit comments