-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWacsdkProjectDeleteCommand.cs
More file actions
63 lines (52 loc) · 2.5 KB
/
WacsdkProjectDeleteCommand.cs
File metadata and controls
63 lines (52 loc) · 2.5 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
using OwlCore.Diagnostics;
using OwlCore.Storage;
using System.CommandLine;
using WindowsAppCommunity.Sdk.Nomad;
namespace WindowsAppCommunity.CommandLine.Project
{
/// <summary>
/// Command to delete an existing project.
/// </summary>
public class WacsdkProjectDeleteCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="WacsdkProjectDeleteCommand"/> class.
/// </summary>
public WacsdkProjectDeleteCommand(WacsdkCommandConfig config, Option<string> repoOption)
: base(name: "delete", description: "Deletes a project.")
{
var projectIdOption = new Option<string>(
name: "--project-id",
description: "The ID of the project to delete.")
{
IsRequired = true
};
AddOption(repoOption);
AddOption(projectIdOption);
this.SetHandler(InvokeAsync, repoOption, projectIdOption);
Config = config;
}
/// <summary>
/// Shared command configuration.
/// </summary>
public WacsdkCommandConfig Config { get; }
/// <summary>
/// Handles the command.
/// </summary>
public async Task InvokeAsync(string repoId, string projectId)
{
var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false);
Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}");
var repoSettings = new WacsdkNomadSettings(thisRepoStorage);
await repoSettings.LoadAsync(Config.CancellationToken);
var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs);
Logger.LogInformation($"Getting project {projectId}");
var project = (ModifiableProject)await repositoryContainer.ProjectRepository.GetAsync(projectId, Config.CancellationToken);
Logger.LogInformation($"Deleting project {projectId}");
await repositoryContainer.ProjectRepository.DeleteAsync(project, Config.CancellationToken);
Logger.LogInformation($"Saving repository changes");
await repoSettings.SaveAsync(Config.CancellationToken);
Logger.LogInformation($"Deleted project {projectId}");
}
}
}