Skip to content

Commit 10970af

Browse files
authored
Merge pull request #3 from WindowsAppCommunity/feat/entity-delete-commands
feat(cli): add delete commands for user, project, publisher
2 parents 7b86af8 + 6caca99 commit 10970af

File tree

6 files changed

+201
-8
lines changed

6 files changed

+201
-8
lines changed

src/Commands/Project/WacsdkProjectCommands.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,22 @@ public WacsdkProjectCommands(WacsdkCommandConfig config, Option<string> repoOpti
5353
AddCommand(new WacsdkProjectGetCommand(config, repoOption));
5454
AddCommand(new WacsdkProjectCreateCommand(config, repoOption, nameOption, descriptionOption));
5555
AddCommand(new WacsdkProjectListCommand(config, repoOption));
56+
AddCommand(new WacsdkProjectDeleteCommand(config, repoOption));
5657

5758
// Add entity property management commands
5859
AddCommand(new EntityNameCommand(config, repoOption, projectIdOption, valueOption));
5960
AddCommand(new EntityDescription(config, repoOption, projectIdOption, valueOption));
6061
AddCommand(new EntityExtendedDescription(config, repoOption, projectIdOption, valueOption));
6162
AddCommand(new EntityIsUnlistedCommand(config, repoOption, projectIdOption, boolValueOption));
6263
AddCommand(new EntityForgetMeCommand(config, repoOption, projectIdOption, nullableBoolValueOption));
63-
64+
6465
// Add collection management commands
6566
AddCommand(new ConnectionsCommand(config, repoOption, projectIdOption, connectionIdOption, connectionValueOption));
6667
AddCommand(new EntityImagesCommand(config, repoOption, projectIdOption, imagePathOption, optionalImageIdOption, requiredImageIdOption, imageNameOption));
6768
AddCommand(new LinksCommand(config, repoOption, projectIdOption, linkIdOption, nameOption, urlOption, descriptionOption));
6869
AddCommand(new UserRolesCommand(config, repoOption, projectIdOption, userIdOption, roleIdOption, roleNameOption, roleDescriptionOption));
6970
AddCommand(new AccentColorCommand(config, repoOption, projectIdOption, colorOption));
70-
71+
7172
// Add project-specific commands
7273
AddCommand(new CategoryCommand(config, repoOption, projectIdOption, categoryOption));
7374
AddCommand(new FeaturesCommand(config, repoOption, projectIdOption, featureOption));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using OwlCore.Diagnostics;
2+
using OwlCore.Storage;
3+
using System.CommandLine;
4+
using WindowsAppCommunity.Sdk.Nomad;
5+
6+
namespace WindowsAppCommunity.CommandLine.Project
7+
{
8+
/// <summary>
9+
/// Command to delete an existing project.
10+
/// </summary>
11+
public class WacsdkProjectDeleteCommand : Command
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="WacsdkProjectDeleteCommand"/> class.
15+
/// </summary>
16+
public WacsdkProjectDeleteCommand(WacsdkCommandConfig config, Option<string> repoOption)
17+
: base(name: "delete", description: "Deletes a project.")
18+
{
19+
var projectIdOption = new Option<string>(
20+
name: "--project-id",
21+
description: "The ID of the project to delete.")
22+
{
23+
IsRequired = true
24+
};
25+
26+
AddOption(repoOption);
27+
AddOption(projectIdOption);
28+
this.SetHandler(InvokeAsync, repoOption, projectIdOption);
29+
30+
Config = config;
31+
}
32+
33+
/// <summary>
34+
/// Shared command configuration.
35+
/// </summary>
36+
public WacsdkCommandConfig Config { get; }
37+
38+
/// <summary>
39+
/// Handles the command.
40+
/// </summary>
41+
public async Task InvokeAsync(string repoId, string projectId)
42+
{
43+
var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false);
44+
45+
Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}");
46+
var repoSettings = new WacsdkNomadSettings(thisRepoStorage);
47+
await repoSettings.LoadAsync(Config.CancellationToken);
48+
49+
var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs);
50+
51+
Logger.LogInformation($"Getting project {projectId}");
52+
var project = (ModifiableProject)await repositoryContainer.ProjectRepository.GetAsync(projectId, Config.CancellationToken);
53+
54+
Logger.LogInformation($"Deleting project {projectId}");
55+
await repositoryContainer.ProjectRepository.DeleteAsync(project, Config.CancellationToken);
56+
57+
Logger.LogInformation($"Saving repository changes");
58+
await repoSettings.SaveAsync(Config.CancellationToken);
59+
60+
Logger.LogInformation($"Deleted project {projectId}");
61+
}
62+
}
63+
}

src/Commands/Publisher/WacsdkPublisherCommands.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public WacsdkPublisherCommands(WacsdkCommandConfig config, Option<string> repoOp
5757
AddCommand(new WacsdkPublisherGetCommand(config, repoOption));
5858
AddCommand(new WacsdkPublisherCreateCommand(config, repoOption));
5959
AddCommand(new WacsdkPublisherListCommand(config, repoOption));
60+
AddCommand(new WacsdkPublisherDeleteCommand(config, repoOption));
6061

6162
// Add entity property management commands
6263
AddCommand(new EntityNameCommand(config, repoOption, publisherIdOption, valueOption));
6364
AddCommand(new EntityDescription(config, repoOption, publisherIdOption, valueOption));
6465
AddCommand(new EntityExtendedDescription(config, repoOption, publisherIdOption, valueOption));
6566
AddCommand(new EntityIsUnlistedCommand(config, repoOption, publisherIdOption, boolValueOption));
6667
AddCommand(new EntityForgetMeCommand(config, repoOption, publisherIdOption, nullableBoolValueOption));
67-
68+
6869
// Add collection management commands
6970
AddCommand(new ConnectionsCommand(config, repoOption, publisherIdOption, connectionIdOption, connectionValueOption));
7071
AddCommand(new EntityImagesCommand(config, repoOption, publisherIdOption, imagePathOption, requiredImageIdOption, optionalImageIdOption, imageNameOption));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using OwlCore.Diagnostics;
2+
using OwlCore.Storage;
3+
using System.CommandLine;
4+
using WindowsAppCommunity.Sdk.Nomad;
5+
6+
namespace WindowsAppCommunity.CommandLine.Publisher
7+
{
8+
/// <summary>
9+
/// Command to delete an existing publisher.
10+
/// </summary>
11+
public class WacsdkPublisherDeleteCommand : Command
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="WacsdkPublisherDeleteCommand"/> class.
15+
/// </summary>
16+
public WacsdkPublisherDeleteCommand(WacsdkCommandConfig config, Option<string> repoOption)
17+
: base(name: "delete", description: "Deletes a publisher.")
18+
{
19+
var publisherIdOption = new Option<string>(
20+
name: "--publisher-id",
21+
description: "The ID of the publisher to delete.")
22+
{
23+
IsRequired = true
24+
};
25+
26+
AddOption(repoOption);
27+
AddOption(publisherIdOption);
28+
this.SetHandler(InvokeAsync, repoOption, publisherIdOption);
29+
30+
Config = config;
31+
}
32+
33+
/// <summary>
34+
/// Shared command configuration.
35+
/// </summary>
36+
public WacsdkCommandConfig Config { get; }
37+
38+
/// <summary>
39+
/// Handles the command.
40+
/// </summary>
41+
public async Task InvokeAsync(string repoId, string publisherId)
42+
{
43+
var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false);
44+
45+
Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}");
46+
var repoSettings = new WacsdkNomadSettings(thisRepoStorage);
47+
await repoSettings.LoadAsync(Config.CancellationToken);
48+
49+
var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs);
50+
51+
Logger.LogInformation($"Getting publisher {publisherId}");
52+
var publisher = (ModifiablePublisher)await repositoryContainer.PublisherRepository.GetAsync(publisherId, Config.CancellationToken);
53+
54+
Logger.LogInformation($"Deleting publisher {publisherId}");
55+
await repositoryContainer.PublisherRepository.DeleteAsync(publisher, Config.CancellationToken);
56+
57+
Logger.LogInformation($"Saving repository changes");
58+
await repoSettings.SaveAsync(Config.CancellationToken);
59+
60+
Logger.LogInformation($"Deleted publisher {publisherId}");
61+
}
62+
}
63+
}

src/Commands/User/WacsdkUserCommands.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@ public WacsdkUserCommands(WacsdkCommandConfig config, Option<string> repoOption)
4444
var roleIdOption = new Option<string>("--role-id", "The ID of the role.");
4545
var roleNameOption = new Option<string>("--role-name", "The name of the role.");
4646
var roleDescriptionOption = new Option<string>("--role-description", "The description of the role.");
47-
48-
47+
48+
4949
// Add high-level user operations
5050
AddCommand(new WacsdkUserGetCommand(config, repoOption));
5151
AddCommand(new WacsdkUserCreateCommand(config, repoOption, nameOption, descriptionOption));
52-
AddCommand(new WacsdkUserListCommand(config, repoOption));
53-
52+
AddCommand(new WacsdkUserListCommand(config, repoOption));
53+
AddCommand(new WacsdkUserDeleteCommand(config, repoOption));
54+
5455
// Add entity property management commands
5556
AddCommand(new EntityNameCommand(config, repoOption, userIdOption, valueOption));
5657
AddCommand(new EntityDescription(config, repoOption, userIdOption, valueOption));
5758
AddCommand(new EntityExtendedDescription(config, repoOption, userIdOption, valueOption));
5859
AddCommand(new EntityIsUnlistedCommand(config, repoOption, userIdOption, boolValueOption));
5960
AddCommand(new EntityForgetMeCommand(config, repoOption, userIdOption, nullableBoolValueOption));
60-
61+
6162
// Add collection management commands
6263
AddCommand(new ConnectionsCommand(config, repoOption, userIdOption, connectionIdOption, connectionValueOption));
6364
AddCommand(new EntityImagesCommand(config, repoOption, userIdOption, imagePathOption, imageNameOption, optionalImageIdOption, requiredImageIdOption));
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using OwlCore.Diagnostics;
2+
using OwlCore.Storage;
3+
using System.CommandLine;
4+
using WindowsAppCommunity.Sdk.Nomad;
5+
6+
namespace WindowsAppCommunity.CommandLine.User
7+
{
8+
/// <summary>
9+
/// Command to delete an existing user.
10+
/// </summary>
11+
public class WacsdkUserDeleteCommand : Command
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="WacsdkUserDeleteCommand"/> class.
15+
/// </summary>
16+
public WacsdkUserDeleteCommand(WacsdkCommandConfig config, Option<string> repoOption)
17+
: base(name: "delete", description: "Deletes a user.")
18+
{
19+
var userIdOption = new Option<string>(
20+
name: "--user-id",
21+
description: "The ID of the user to delete.")
22+
{
23+
IsRequired = true
24+
};
25+
26+
AddOption(repoOption);
27+
AddOption(userIdOption);
28+
29+
this.SetHandler(InvokeAsync, repoOption, userIdOption);
30+
31+
Config = config;
32+
}
33+
34+
/// <summary>
35+
/// Shared command configuration.
36+
/// </summary>
37+
public WacsdkCommandConfig Config { get; }
38+
39+
/// <summary>
40+
/// Handles the command.
41+
/// </summary>
42+
public async Task InvokeAsync(string repoId, string userId)
43+
{
44+
var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false);
45+
46+
Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}");
47+
var repoSettings = new WacsdkNomadSettings(thisRepoStorage);
48+
await repoSettings.LoadAsync(Config.CancellationToken);
49+
50+
var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs);
51+
52+
Logger.LogInformation($"Getting user {userId}");
53+
var user = (ModifiableUser)await repositoryContainer.UserRepository.GetAsync(userId, Config.CancellationToken);
54+
55+
Logger.LogInformation($"Deleting user {userId}");
56+
await repositoryContainer.UserRepository.DeleteAsync(user, Config.CancellationToken);
57+
58+
Logger.LogInformation($"Saving repository changes");
59+
await repoSettings.SaveAsync(Config.CancellationToken);
60+
61+
Logger.LogInformation($"Deleted user {userId}");
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)