88638d774a
Two verified-absent parity gaps between the service layer and the CLI / ManagementActor command surface, both left as follow-ups by the 2026-05-11 design plans. (1) area move. AreaService.MoveAreaAsync had existed since the deployment topology page shipped but was reachable only from the Blazor UI. Adds MoveAreaCommand(AreaId, NewParentAreaId?) to Commons, a ManagementActor dispatch arm delegating straight to AreaService.MoveAreaAsync (not-found / self-parent / descendant-cycle / cross-site / name-collision all surface as the standard curated ManagementCommandException failure response; the service writes its own "Move" audit row), and the CLI verb `site area move --id [--parent-id]`. Omitting --parent-id moves the area to the site root, matching the command's nullable NewParentAreaId. The command carries the SAME any-of [Designer, Deployer] gate as CreateArea/UpdateArea/DeleteArea (arch-review C6): re-parenting is the same structural authoring act, exposed on the same two surfaces. Placed under the existing `site area` group rather than a new top-level `area` group, alongside its create/update/delete siblings. (2) template folder verbs. The five folder management commands have been handled by ManagementActor since the folder-hierarchy plan, but the promised CLI surface was never written. Adds `template folder list|create|rename|move|reorder|delete` mapping 1:1 onto ListTemplateFolders / CreateTemplateFolder / RenameTemplateFolder / MoveTemplateFolder / ReorderTemplateFolder / DeleteTemplateFolder. --parent-id is omitted to target the tree root; --direction takes the lowercase literals up/down, validated at parse time by AcceptOnlyFromAmong (same case-sensitive contract as the audit --channel/--kind/--status options). Follow-on updates: the frozen authorization matrix gains its MoveArea entry (reflection-driven, so a missing entry would have failed CI); CommandTreeTests pins both new verb sets plus the omit-parent-id-means-root parse behaviour and registry round-trips; ManagementActorTests covers the MoveArea role gate and the delegate-to-service success/root/cycle/not-found paths; the CLI README and Component-ManagementService.md document the new surface (the latter also gained the previously-undocumented ReorderTemplateFolder); both plan docs' follow-up lines are marked done.
231 lines
12 KiB
C#
231 lines
12 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
public static class SiteCommands
|
|
{
|
|
/// <summary>
|
|
/// Builds the <c>site</c> command group and all its subcommands.
|
|
/// </summary>
|
|
/// <param name="urlOption">Global management URL option.</param>
|
|
/// <param name="formatOption">Global output format option.</param>
|
|
/// <param name="usernameOption">Global username option.</param>
|
|
/// <param name="passwordOption">Global password option.</param>
|
|
/// <returns>The configured <c>site</c> command with all subcommands attached.</returns>
|
|
public static Command Build(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var command = new Command("site") { Description = "Manage sites" };
|
|
|
|
command.Add(BuildList(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildGet(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildCreate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildUpdate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDelete(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDeployArtifacts(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildArea(urlOption, formatOption, usernameOption, passwordOption));
|
|
|
|
return command;
|
|
}
|
|
|
|
private static Command BuildGet(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Site ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get a site by ID" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new GetSiteCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildList(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var cmd = new Command("list") { Description = "List all sites" };
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new ListSitesCommand());
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildCreate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var nameOption = new Option<string>("--name") { Description = "Site name", Required = true };
|
|
var identifierOption = new Option<string>("--identifier") { Description = "Site identifier", Required = true };
|
|
var descOption = new Option<string?>("--description") { Description = "Site description" };
|
|
var nodeAOption = new Option<string?>("--node-a-address") { Description = "Akka address for Node A" };
|
|
var nodeBOption = new Option<string?>("--node-b-address") { Description = "Akka address for Node B" };
|
|
var grpcNodeAOption = new Option<string?>("--grpc-node-a-address") { Description = "gRPC address for Node A" };
|
|
var grpcNodeBOption = new Option<string?>("--grpc-node-b-address") { Description = "gRPC address for Node B" };
|
|
|
|
var cmd = new Command("create") { Description = "Create a new site" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(identifierOption);
|
|
cmd.Add(descOption);
|
|
cmd.Add(nodeAOption);
|
|
cmd.Add(nodeBOption);
|
|
cmd.Add(grpcNodeAOption);
|
|
cmd.Add(grpcNodeBOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var identifier = result.GetValue(identifierOption)!;
|
|
var desc = result.GetValue(descOption);
|
|
var nodeA = result.GetValue(nodeAOption);
|
|
var nodeB = result.GetValue(nodeBOption);
|
|
var grpcNodeA = result.GetValue(grpcNodeAOption);
|
|
var grpcNodeB = result.GetValue(grpcNodeBOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new CreateSiteCommand(name, identifier, desc, nodeA, nodeB, grpcNodeA, grpcNodeB));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildUpdate(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Site ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "Site name", Required = true };
|
|
var descOption = new Option<string?>("--description") { Description = "Site description" };
|
|
var nodeAOption = new Option<string?>("--node-a-address") { Description = "Akka address for Node A" };
|
|
var nodeBOption = new Option<string?>("--node-b-address") { Description = "Akka address for Node B" };
|
|
var grpcNodeAOption = new Option<string?>("--grpc-node-a-address") { Description = "gRPC address for Node A" };
|
|
var grpcNodeBOption = new Option<string?>("--grpc-node-b-address") { Description = "gRPC address for Node B" };
|
|
|
|
var cmd = new Command("update") { Description = "Update an existing site" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(nameOption);
|
|
cmd.Add(descOption);
|
|
cmd.Add(nodeAOption);
|
|
cmd.Add(nodeBOption);
|
|
cmd.Add(grpcNodeAOption);
|
|
cmd.Add(grpcNodeBOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var name = result.GetValue(nameOption)!;
|
|
var desc = result.GetValue(descOption);
|
|
var nodeA = result.GetValue(nodeAOption);
|
|
var nodeB = result.GetValue(nodeBOption);
|
|
var grpcNodeA = result.GetValue(grpcNodeAOption);
|
|
var grpcNodeB = result.GetValue(grpcNodeBOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new UpdateSiteCommand(id, name, desc, nodeA, nodeB, grpcNodeA, grpcNodeB));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDelete(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Site ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete a site" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new DeleteSiteCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildArea(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var group = new Command("area") { Description = "Manage areas" };
|
|
|
|
var siteIdOption = new Option<int>("--site-id") { Description = "Site ID", Required = true };
|
|
var listCmd = new Command("list") { Description = "List areas for a site" };
|
|
listCmd.Add(siteIdOption);
|
|
listCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var siteId = result.GetValue(siteIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new ListAreasCommand(siteId));
|
|
});
|
|
group.Add(listCmd);
|
|
|
|
var createSiteIdOption = new Option<int>("--site-id") { Description = "Site ID", Required = true };
|
|
var nameOption = new Option<string>("--name") { Description = "Area name", Required = true };
|
|
var parentOption = new Option<int?>("--parent-id") { Description = "Parent area ID" };
|
|
var createCmd = new Command("create") { Description = "Create an area" };
|
|
createCmd.Add(createSiteIdOption);
|
|
createCmd.Add(nameOption);
|
|
createCmd.Add(parentOption);
|
|
createCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var siteId = result.GetValue(createSiteIdOption);
|
|
var name = result.GetValue(nameOption)!;
|
|
var parentId = result.GetValue(parentOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new CreateAreaCommand(siteId, name, parentId));
|
|
});
|
|
group.Add(createCmd);
|
|
|
|
var updateIdOption = new Option<int>("--id") { Description = "Area ID", Required = true };
|
|
var updateNameOption = new Option<string>("--name") { Description = "New area name", Required = true };
|
|
var updateCmd = new Command("update") { Description = "Update an area" };
|
|
updateCmd.Add(updateIdOption);
|
|
updateCmd.Add(updateNameOption);
|
|
updateCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(updateIdOption);
|
|
var name = result.GetValue(updateNameOption)!;
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new UpdateAreaCommand(id, name));
|
|
});
|
|
group.Add(updateCmd);
|
|
|
|
// Omitting --parent-id moves the area to the site root, matching
|
|
// AreaService.MoveAreaAsync's null newParentAreaId contract.
|
|
var moveIdOption = new Option<int>("--id") { Description = "Area ID", Required = true };
|
|
var moveParentOption = new Option<int?>("--parent-id") { Description = "New parent area ID; omit to move to the site root" };
|
|
var moveCmd = new Command("move") { Description = "Move an area under a new parent area (or to the site root)" };
|
|
moveCmd.Add(moveIdOption);
|
|
moveCmd.Add(moveParentOption);
|
|
moveCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(moveIdOption);
|
|
var parentId = result.GetValue(moveParentOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new MoveAreaCommand(id, parentId));
|
|
});
|
|
group.Add(moveCmd);
|
|
|
|
var deleteIdOption = new Option<int>("--id") { Description = "Area ID", Required = true };
|
|
var deleteCmd = new Command("delete") { Description = "Delete an area" };
|
|
deleteCmd.Add(deleteIdOption);
|
|
deleteCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(deleteIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new DeleteAreaCommand(id));
|
|
});
|
|
group.Add(deleteCmd);
|
|
|
|
return group;
|
|
}
|
|
|
|
private static Command BuildDeployArtifacts(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var siteIdOption = new Option<int?>("--site-id") { Description = "Target site ID (all sites if omitted)" };
|
|
var cmd = new Command("deploy-artifacts") { Description = "Deploy artifacts to site(s)" };
|
|
cmd.Add(siteIdOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var siteId = result.GetValue(siteIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new MgmtDeployArtifactsCommand(siteId));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|