feat(cli,management): close area-move and template-folder CLI parity gaps

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.
This commit is contained in:
Joseph Doherty
2026-08-01 11:14:48 -04:00
parent e0851e3e17
commit 88638d774a
11 changed files with 482 additions and 6 deletions
@@ -183,6 +183,23 @@ public static class SiteCommands
});
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);
@@ -29,11 +29,116 @@ public static class TemplateCommands
command.Add(BuildNativeAlarmSource(urlOption, formatOption, usernameOption, passwordOption));
command.Add(BuildScript(urlOption, formatOption, usernameOption, passwordOption));
command.Add(BuildComposition(urlOption, formatOption, usernameOption, passwordOption));
command.Add(BuildFolder(urlOption, formatOption, usernameOption, passwordOption));
command.Add(BuildResyncMembers(urlOption, formatOption, usernameOption, passwordOption));
return command;
}
/// <summary>
/// Builds the <c>template folder</c> subgroup — the CLI surface for the template
/// folder hierarchy management commands (folders are a Central UI organizational
/// device only; they have no effect on template resolution or flattening).
/// Omitting <c>--parent-id</c> on create/move places the folder at the tree root,
/// matching the nullable <c>ParentFolderId</c> on the underlying commands.
/// </summary>
private static Command BuildFolder(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
{
var group = new Command("folder") { Description = "Manage template folders" };
var listCmd = new Command("list") { Description = "List all template folders" };
listCmd.SetAction(async (ParseResult result) =>
{
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption, new ListTemplateFoldersCommand());
});
group.Add(listCmd);
var createNameOption = new Option<string>("--name") { Description = "Folder name", Required = true };
var createParentOption = new Option<int?>("--parent-id") { Description = "Parent folder ID; omit to create at the tree root" };
var createCmd = new Command("create") { Description = "Create a template folder" };
createCmd.Add(createNameOption);
createCmd.Add(createParentOption);
createCmd.SetAction(async (ParseResult result) =>
{
var name = result.GetValue(createNameOption)!;
var parentId = result.GetValue(createParentOption);
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new CreateTemplateFolderCommand(name, parentId));
});
group.Add(createCmd);
var renameIdOption = new Option<int>("--id") { Description = "Folder ID", Required = true };
var renameNameOption = new Option<string>("--name") { Description = "New folder name", Required = true };
var renameCmd = new Command("rename") { Description = "Rename a template folder" };
renameCmd.Add(renameIdOption);
renameCmd.Add(renameNameOption);
renameCmd.SetAction(async (ParseResult result) =>
{
var id = result.GetValue(renameIdOption);
var name = result.GetValue(renameNameOption)!;
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new RenameTemplateFolderCommand(id, name));
});
group.Add(renameCmd);
var moveIdOption = new Option<int>("--id") { Description = "Folder ID", Required = true };
var moveParentOption = new Option<int?>("--parent-id") { Description = "New parent folder ID; omit to move to the tree root" };
var moveCmd = new Command("move") { Description = "Move a template folder under a new parent folder (or to the tree 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 MoveTemplateFolderCommand(id, parentId));
});
group.Add(moveCmd);
var reorderIdOption = new Option<int>("--id") { Description = "Folder ID", Required = true };
var reorderDirectionOption = new Option<string>("--direction")
{
Description = "Reorder direction: 'up' swaps with the previous sibling, 'down' with the next",
Required = true
};
reorderDirectionOption.AcceptOnlyFromAmong("up", "down");
var reorderCmd = new Command("reorder") { Description = "Reorder a template folder among its siblings" };
reorderCmd.Add(reorderIdOption);
reorderCmd.Add(reorderDirectionOption);
reorderCmd.SetAction(async (ParseResult result) =>
{
var id = result.GetValue(reorderIdOption);
// AcceptOnlyFromAmong has already rejected anything but the two literals,
// so this maps a validated value rather than parsing untrusted input.
var direction = result.GetValue(reorderDirectionOption) == "up"
? ReorderDirection.Up
: ReorderDirection.Down;
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new ReorderTemplateFolderCommand(id, direction));
});
group.Add(reorderCmd);
var deleteIdOption = new Option<int>("--id") { Description = "Folder ID", Required = true };
var deleteCmd = new Command("delete") { Description = "Delete a template folder (fails if it contains subfolders or templates)" };
deleteCmd.Add(deleteIdOption);
deleteCmd.SetAction(async (ParseResult result) =>
{
var id = result.GetValue(deleteIdOption);
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new DeleteTemplateFolderCommand(id));
});
group.Add(deleteCmd);
return group;
}
private static Command BuildResyncMembers(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
{
var idOption = new Option<int>("--id") { Description = "Template ID (its derived subtree is included)", Required = true };
+93
View File
@@ -431,6 +431,84 @@ scadabridge --url <url> template resync-members --id <int>
|--------|----------|-------------|
| `--id` | yes | Template ID (its derived subtree is included) |
#### `template folder list`
List all template folders. Folders are a Central UI organizational device only — they
have no effect on template resolution or flattening.
```sh
scadabridge --url <url> template folder list
```
Takes no options beyond the global ones.
#### `template folder create`
Create a template folder. Omit `--parent-id` to create it at the tree root. Sibling
names must be unique (case-insensitive).
```sh
scadabridge --url <url> template folder create --name <string> [--parent-id <int>]
```
| Option | Required | Description |
|--------|----------|-------------|
| `--name` | yes | Folder name |
| `--parent-id` | no | Parent folder ID; omit to create at the tree root |
#### `template folder rename`
Rename a template folder. Enforces sibling-name uniqueness.
```sh
scadabridge --url <url> template folder rename --id <int> --name <string>
```
| Option | Required | Description |
|--------|----------|-------------|
| `--id` | yes | Folder ID |
| `--name` | yes | New folder name |
#### `template folder move`
Move a template folder under a new parent folder. Omit `--parent-id` to move it to the
tree root. Rejects cycles (a folder cannot move under one of its own descendants).
```sh
scadabridge --url <url> template folder move --id <int> [--parent-id <int>]
```
| Option | Required | Description |
|--------|----------|-------------|
| `--id` | yes | Folder ID to move |
| `--parent-id` | no | New parent folder ID; omit to move to the tree root |
#### `template folder reorder`
Swap a folder's `SortOrder` with an adjacent sibling. `up` swaps with the previous
sibling, `down` with the next; reordering past either end is a no-op.
```sh
scadabridge --url <url> template folder reorder --id <int> --direction <up|down>
```
| Option | Required | Description |
|--------|----------|-------------|
| `--id` | yes | Folder ID |
| `--direction` | yes | `up` or `down` (lowercase literals only) |
#### `template folder delete`
Delete a template folder. Blocked if the folder still contains any subfolders or templates.
```sh
scadabridge --url <url> template folder delete --id <int>
```
| Option | Required | Description |
|--------|----------|-------------|
| `--id` | yes | Folder ID |
---
### `instance` — Manage instances
@@ -831,6 +909,21 @@ scadabridge --url <url> site area update --id <int> --name <string>
| `--id` | yes | Area ID |
| `--name` | yes | Area name |
#### `site area move`
Re-parent an area within its own site. Omit `--parent-id` to move the area to the
site root. Rejected for: self-parent, moving under one of the area's own descendants
(cycle), a parent in a different site, and a sibling name collision at the target level.
```sh
scadabridge --url <url> site area move --id <int> [--parent-id <int>]
```
| Option | Required | Description |
|--------|----------|-------------|
| `--id` | yes | Area ID to move |
| `--parent-id` | no | New parent area ID; omit to move to the site root |
#### `site area delete`
Delete an area. Fails if any instances are assigned to it.
@@ -9,3 +9,10 @@ public record ListAreasCommand(int SiteId);
public record CreateAreaCommand(int SiteId, string Name, int? ParentAreaId);
public record DeleteAreaCommand(int AreaId);
public record UpdateAreaCommand(int AreaId, string Name);
/// <summary>
/// Re-parents an area within its own site. <c>NewParentAreaId == null</c> moves the
/// area to the site root. Rejected by the handler for self-parent, descendant-parent
/// (cycle), cross-site parent, and sibling name collision at the target level.
/// </summary>
public record MoveAreaCommand(int AreaId, int? NewParentAreaId);
@@ -225,7 +225,8 @@ public class ManagementActor : ReceiveActor
// Area management — any-of [Designer, Deployer] (arch-review C6).
// Exposed both in the Designer tooling and inside the Central UI
// Deployment Topology workflow (RequireDeployment), so both roles qualify.
CreateAreaCommand or UpdateAreaCommand or DeleteAreaCommand => AreaManagers,
CreateAreaCommand or UpdateAreaCommand or MoveAreaCommand
or DeleteAreaCommand => AreaManagers,
// Designer operations
CreateTemplateCommand or UpdateTemplateCommand or DeleteTemplateCommand
@@ -362,6 +363,7 @@ public class ManagementActor : ReceiveActor
CreateAreaCommand cmd => await HandleCreateArea(sp, cmd, user.Username),
DeleteAreaCommand cmd => await HandleDeleteArea(sp, cmd, user.Username),
UpdateAreaCommand cmd => await HandleUpdateArea(sp, cmd, user.Username),
MoveAreaCommand cmd => await HandleMoveArea(sp, cmd, user.Username),
// Data Connections
ListDataConnectionsCommand cmd => await HandleListDataConnections(sp, cmd),
@@ -3116,6 +3118,22 @@ public class ManagementActor : ReceiveActor
return area;
}
/// <summary>
/// Re-parents an area within its site, delegating every validation rule
/// (not-found, self-parent, descendant-parent cycle, cross-site parent,
/// sibling name collision) to <c>AreaService.MoveAreaAsync</c>. A null
/// <c>NewParentAreaId</c> moves the area to the site root. Failures surface
/// as the standard curated <see cref="ManagementCommandException"/> failure
/// response, matching the sibling folder/template move handlers. The service
/// writes the "Move" audit row itself, so this handler does not audit again.
/// </summary>
private static async Task<object?> HandleMoveArea(IServiceProvider sp, MoveAreaCommand cmd, string user)
{
var svc = sp.GetRequiredService<AreaService>();
var result = await svc.MoveAreaAsync(cmd.AreaId, cmd.NewParentAreaId, user);
return result.IsSuccess ? result.Value : throw new ManagementCommandException(result.Error);
}
// ========================================================================
// Remote Query handlers
// ========================================================================