Skip to content

Commit a5fd528

Browse files
Add confirmation when deleting projects (#82)
1 parent 860d7cc commit a5fd528

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed
Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
11
using System;
22
using System.Management.Automation;
3-
using Eryph.ClientRuntime;
43
using Eryph.ComputeClient.Models;
54
using JetBrains.Annotations;
65

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
812
{
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; }
2722

28-
private bool _nowait;
23+
[Parameter]
24+
public SwitchParameter NoWait { get; set; }
2925

26+
private bool _yesToAll;
27+
private bool _noToAll;
3028

31-
protected override void ProcessRecord()
29+
protected override void ProcessRecord()
30+
{
31+
foreach (var id in Id)
3232
{
33-
foreach (var id in Id)
33+
Project project;
34+
try
3435
{
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;
3742
}
3843

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+
}
4049

50+
WaitForProject(Factory.CreateProjectsClient().Delete(id), NoWait, false, id);
51+
}
4152
}
42-
}
53+
}

0 commit comments

Comments
 (0)