cdd65beb6c
Closes the four remaining items in the 2026-06-24 template-inheritance/CLI follow-up tracker. #4 — CLI `instance set-bindings` can now set DataSourceReferenceOverride. `--bindings` accepts an optional 3rd element per entry: [attributeName, dataConnectionId, dataSourceReferenceOverride]. A string sets the override; a JSON null or an omitted 3rd element leaves it unset (template default). TryParseBindings accepts 2- or 3-element entries and rejects a non-string/non-null 3rd element or 4+ elements with a clean error. Previously the CLI sent the override as null and silently wiped any existing one (only a raw POST /management could set it). #5 — `template update` is partial, not full-replace (fixed server-side so all clients benefit). UpdateTemplateAsync now uses leave-unchanged semantics: a null description keeps the stored value (pass "" to clear); a null parentTemplateId keeps the existing parent. Parent stays immutable — a non-null differing value is still rejected — but omitting --parent-id is now a no-op instead of failing every derived-template update. #6 — compact `template list`/`get` table output + `--detail`. Table output is now id/name/description/parent/derived + member counts (#attrs/#alarms/ #scripts/#comps/#nativeAlarms) via TemplateTableProjection, fed through a new optional tableProjector seam on CommandHelpers. `--detail` restores the full dump. JSON output is left untouched (always full) so machine consumers are unaffected — the projector only runs on the table path. #8 — structured deploy-time validation error. New ValidationResult.SummarizeErrors() (Commons) returns a grouped, capped summary: leading total count, one line per ValidationCategory, and a per-module rollup (canonical name up to its last dot) with counts + "... and N more module(s)" caps. DeploymentService uses it for the "Pre-deployment validation failed" message and logs the full per-entry list via LogWarning. Replaces the flat semicolon-joined dump that became a wall of text for instances with 50-194 unbound attributes. Tests: +8 Commons (SummarizeErrors), +8 CLI (4 binding 3-element / 4 table projection), +2 net TemplateEngine (partial-update). Affected suites green: Commons 587, CLI 341, TemplateEngine 447, DeploymentManager 101, ManagementService 230, CentralUI 866; full solution builds 0/0. Docs: Component-DeploymentManager.md "Validation Error Reporting"; CLI README (set-bindings 3-element form, template update leave-unchanged, list/get --detail); UpdateTemplateCommand doc; known-issues tracker #4/#5/#6/#8 resolved (all 8 items now closed).
512 lines
25 KiB
C#
512 lines
25 KiB
C#
using System.CommandLine;
|
|
using System.CommandLine.Parsing;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
public static class InstanceCommands
|
|
{
|
|
/// <summary>
|
|
/// Builds the instance command and its subcommands.
|
|
/// </summary>
|
|
/// <param name="urlOption">The URL option.</param>
|
|
/// <param name="formatOption">The format option.</param>
|
|
/// <param name="usernameOption">The username option.</param>
|
|
/// <param name="passwordOption">The password option.</param>
|
|
/// <returns>The instance command with all subcommands.</returns>
|
|
public static Command Build(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var command = new Command("instance") { Description = "Manage instances" };
|
|
|
|
command.Add(BuildList(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildGet(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildCreate(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildSetBindings(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildSetOverrides(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildImportOverrides(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildAlarmOverride(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildNativeAlarmSourceOverride(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildSetArea(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDiff(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDeploy(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildEnable(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDisable(urlOption, formatOption, usernameOption, passwordOption));
|
|
command.Add(BuildDelete(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 = "Instance ID", Required = true };
|
|
var cmd = new Command("get") { Description = "Get an instance 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 GetInstanceCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildSetBindings(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var bindingsOption = new Option<string>("--bindings")
|
|
{
|
|
Description = "JSON array of binding entries. Each entry is either " +
|
|
"[attributeName, dataConnectionId] or " +
|
|
"[attributeName, dataConnectionId, dataSourceReferenceOverride] " +
|
|
"(the 3rd element overrides the attribute's data-source reference; " +
|
|
"pass null or omit it to use the template default). " +
|
|
"NOTE: this REPLACES all bindings for the instance — include the " +
|
|
"override on every entry that needs one, or omitting it clears any " +
|
|
"previously-set override.",
|
|
Required = true
|
|
};
|
|
|
|
var cmd = new Command("set-bindings") { Description = "Set data connection bindings for an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(bindingsOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var bindingsJson = result.GetValue(bindingsOption)!;
|
|
if (!TryParseBindings(bindingsJson, out var bindings, out var error))
|
|
{
|
|
OutputFormatter.WriteError(error!, "INVALID_ARGUMENT");
|
|
return 1;
|
|
}
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetConnectionBindingsCommand(id, bindings!));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parses the <c>--bindings</c> argument — a JSON array of binding entries — into a
|
|
/// typed list. Each entry is either a two-element
|
|
/// <c>[attributeName, dataConnectionId]</c> pair or a three-element
|
|
/// <c>[attributeName, dataConnectionId, dataSourceReferenceOverride]</c> triple. The
|
|
/// optional third element carries the per-instance data-source reference override
|
|
/// (<see cref="ConnectionBinding.DataSourceReferenceOverride"/>); a JSON
|
|
/// <c>null</c> (or an omitted third element) leaves it unset so the template default
|
|
/// applies. Returns <c>false</c> with a descriptive <paramref name="error"/> instead
|
|
/// of throwing when the JSON is malformed, an entry has the wrong arity, or an
|
|
/// element has the wrong type.
|
|
/// </summary>
|
|
/// <param name="json">The JSON string to parse.</param>
|
|
/// <param name="bindings">The parsed bindings list, or null if parsing fails.</param>
|
|
/// <param name="error">The error message if parsing fails, or null on success.</param>
|
|
/// <returns>True if parsing succeeded; false otherwise.</returns>
|
|
internal static bool TryParseBindings(
|
|
string json,
|
|
out List<ConnectionBinding>? bindings,
|
|
out string? error)
|
|
{
|
|
bindings = null;
|
|
error = null;
|
|
try
|
|
{
|
|
var pairs = System.Text.Json.JsonSerializer
|
|
.Deserialize<List<List<System.Text.Json.JsonElement>>>(json);
|
|
if (pairs == null)
|
|
{
|
|
error = "Bindings JSON must be a non-null array of "
|
|
+ "[attributeName, dataConnectionId] or "
|
|
+ "[attributeName, dataConnectionId, dataSourceReferenceOverride] entries.";
|
|
return false;
|
|
}
|
|
|
|
var result = new List<ConnectionBinding>(pairs.Count);
|
|
foreach (var pair in pairs)
|
|
{
|
|
if (pair.Count is not (2 or 3))
|
|
{
|
|
error = "Each binding must be a [attributeName, dataConnectionId] pair, "
|
|
+ "optionally with a third dataSourceReferenceOverride element.";
|
|
return false;
|
|
}
|
|
if (pair[0].ValueKind != System.Text.Json.JsonValueKind.String)
|
|
{
|
|
error = "The first element of each binding (attributeName) must be a string.";
|
|
return false;
|
|
}
|
|
if (pair[1].ValueKind != System.Text.Json.JsonValueKind.Number
|
|
|| !pair[1].TryGetInt32(out var connectionId))
|
|
{
|
|
error = "The second element of each binding (dataConnectionId) must be an integer.";
|
|
return false;
|
|
}
|
|
|
|
string? referenceOverride = null;
|
|
if (pair.Count == 3)
|
|
{
|
|
var third = pair[2];
|
|
if (third.ValueKind == System.Text.Json.JsonValueKind.String)
|
|
{
|
|
referenceOverride = third.GetString();
|
|
}
|
|
else if (third.ValueKind != System.Text.Json.JsonValueKind.Null)
|
|
{
|
|
error = "The third element of each binding (dataSourceReferenceOverride) "
|
|
+ "must be a string or null.";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
result.Add(new ConnectionBinding(pair[0].GetString()!, connectionId, referenceOverride));
|
|
}
|
|
|
|
bindings = result;
|
|
return true;
|
|
}
|
|
catch (System.Text.Json.JsonException ex)
|
|
{
|
|
error = $"Invalid bindings JSON: {ex.Message}";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Parses the <c>--overrides</c> argument — a JSON object of
|
|
/// <c>attributeName -> value</c> pairs — into a typed dictionary. Returns
|
|
/// <c>false</c> with a descriptive <paramref name="error"/> instead of throwing
|
|
/// when the JSON is malformed or null.
|
|
/// </summary>
|
|
/// <param name="json">The JSON string to parse.</param>
|
|
/// <param name="overrides">The parsed overrides dictionary, or null if parsing fails.</param>
|
|
/// <param name="error">The error message if parsing fails, or null on success.</param>
|
|
/// <returns>True if parsing succeeded; false otherwise.</returns>
|
|
internal static bool TryParseOverrides(
|
|
string json,
|
|
out Dictionary<string, string?>? overrides,
|
|
out string? error)
|
|
{
|
|
overrides = null;
|
|
error = null;
|
|
try
|
|
{
|
|
var parsed = System.Text.Json.JsonSerializer
|
|
.Deserialize<Dictionary<string, string?>>(json);
|
|
if (parsed == null)
|
|
{
|
|
error = "Overrides JSON must be a non-null object of attribute name -> value pairs.";
|
|
return false;
|
|
}
|
|
overrides = parsed;
|
|
return true;
|
|
}
|
|
catch (System.Text.Json.JsonException ex)
|
|
{
|
|
error = $"Invalid overrides JSON: {ex.Message}";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static Command BuildList(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var siteIdOption = new Option<int?>("--site-id") { Description = "Filter by site ID" };
|
|
var templateIdOption = new Option<int?>("--template-id") { Description = "Filter by template ID" };
|
|
var searchOption = new Option<string?>("--search") { Description = "Search term" };
|
|
|
|
var cmd = new Command("list") { Description = "List instances" };
|
|
cmd.Add(siteIdOption);
|
|
cmd.Add(templateIdOption);
|
|
cmd.Add(searchOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var siteId = result.GetValue(siteIdOption);
|
|
var templateId = result.GetValue(templateIdOption);
|
|
var search = result.GetValue(searchOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new ListInstancesCommand(siteId, templateId, search));
|
|
});
|
|
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 = "Unique instance name", Required = true };
|
|
var templateIdOption = new Option<int>("--template-id") { Description = "Template ID", Required = true };
|
|
var siteIdOption = new Option<int>("--site-id") { Description = "Site ID", Required = true };
|
|
var areaIdOption = new Option<int?>("--area-id") { Description = "Area ID" };
|
|
|
|
var cmd = new Command("create") { Description = "Create a new instance" };
|
|
cmd.Add(nameOption);
|
|
cmd.Add(templateIdOption);
|
|
cmd.Add(siteIdOption);
|
|
cmd.Add(areaIdOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var name = result.GetValue(nameOption)!;
|
|
var templateId = result.GetValue(templateIdOption);
|
|
var siteId = result.GetValue(siteIdOption);
|
|
var areaId = result.GetValue(areaIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new CreateInstanceCommand(name, templateId, siteId, areaId));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDeploy(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var cmd = new Command("deploy") { Description = "Deploy an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new MgmtDeployInstanceCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildEnable(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var cmd = new Command("enable") { Description = "Enable an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new MgmtEnableInstanceCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDisable(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var cmd = new Command("disable") { Description = "Disable an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new MgmtDisableInstanceCommand(id));
|
|
});
|
|
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 = "Instance ID", Required = true };
|
|
var cmd = new Command("delete") { Description = "Delete an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption, new MgmtDeleteInstanceCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildSetOverrides(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var overridesOption = new Option<string>("--overrides") { Description = "JSON object of attribute name -> value pairs, e.g. {\"Speed\": \"100\", \"Mode\": null}", Required = true };
|
|
|
|
var cmd = new Command("set-overrides") { Description = "Set attribute overrides for an instance" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(overridesOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var overridesJson = result.GetValue(overridesOption)!;
|
|
if (!TryParseOverrides(overridesJson, out var overrides, out var error))
|
|
{
|
|
OutputFormatter.WriteError(error!, "INVALID_ARGUMENT");
|
|
return 1;
|
|
}
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetInstanceOverridesCommand(id, overrides!));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildImportOverrides(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var fileOption = new Option<string>("--file") { Description = "Path to the override CSV file (columns: AttributeName,Value,ElementType)", Required = true };
|
|
|
|
var cmd = new Command("import-overrides") { Description = "Apply attribute overrides from a CSV file" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(fileOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var filePath = result.GetValue(fileOption)!;
|
|
|
|
string csvText;
|
|
try
|
|
{
|
|
csvText = File.ReadAllText(filePath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
OutputFormatter.WriteError($"Cannot read file '{filePath}': {ex.Message}", "FILE_READ_ERROR");
|
|
return 1;
|
|
}
|
|
|
|
var parseResult = OverrideCsvParser.Parse(csvText);
|
|
if (parseResult.Errors.Count > 0)
|
|
{
|
|
foreach (var error in parseResult.Errors)
|
|
OutputFormatter.WriteError(error, "INVALID_CSV");
|
|
return 1;
|
|
}
|
|
|
|
var overrides = parseResult.Rows.ToDictionary(r => r.AttributeName, r => r.Value);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetInstanceOverridesCommand(id, overrides));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildAlarmOverride(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var group = new Command("alarm-override") { Description = "Manage per-instance alarm overrides" };
|
|
|
|
// set
|
|
var setIdOption = new Option<int>("--instance-id") { Description = "Instance ID", Required = true };
|
|
var setAlarmOption = new Option<string>("--alarm") { Description = "Alarm canonical name (e.g., 'TempLevels' or 'Pump.TempSensor.Heat')", Required = true };
|
|
var setConfigOption = new Option<string?>("--trigger-config") { Description = "JSON override for TriggerConfiguration (HiLo: partial merge; others: whole-replace)" };
|
|
var setPriorityOption = new Option<int?>("--priority") { Description = "Priority override (0-1000)" };
|
|
var setCmd = new Command("set") { Description = "Set (upsert) an alarm override on an instance" };
|
|
setCmd.Add(setIdOption); setCmd.Add(setAlarmOption); setCmd.Add(setConfigOption); setCmd.Add(setPriorityOption);
|
|
setCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetInstanceAlarmOverrideCommand(
|
|
result.GetValue(setIdOption),
|
|
result.GetValue(setAlarmOption)!,
|
|
result.GetValue(setConfigOption),
|
|
result.GetValue(setPriorityOption)));
|
|
});
|
|
group.Add(setCmd);
|
|
|
|
// delete
|
|
var delIdOption = new Option<int>("--instance-id") { Description = "Instance ID", Required = true };
|
|
var delAlarmOption = new Option<string>("--alarm") { Description = "Alarm canonical name", Required = true };
|
|
var delCmd = new Command("delete") { Description = "Remove an alarm override on an instance" };
|
|
delCmd.Add(delIdOption); delCmd.Add(delAlarmOption);
|
|
delCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new DeleteInstanceAlarmOverrideCommand(
|
|
result.GetValue(delIdOption),
|
|
result.GetValue(delAlarmOption)!));
|
|
});
|
|
group.Add(delCmd);
|
|
|
|
// list
|
|
var listIdOption = new Option<int>("--instance-id") { Description = "Instance ID", Required = true };
|
|
var listCmd = new Command("list") { Description = "List all alarm overrides for an instance" };
|
|
listCmd.Add(listIdOption);
|
|
listCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new ListInstanceAlarmOverridesCommand(result.GetValue(listIdOption)));
|
|
});
|
|
group.Add(listCmd);
|
|
|
|
return group;
|
|
}
|
|
|
|
private static Command BuildNativeAlarmSourceOverride(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var group = new Command("native-alarm-source")
|
|
{
|
|
Description = "Manage per-instance native alarm source overrides (retarget an inherited binding; blank = inherited)"
|
|
};
|
|
|
|
// set
|
|
var setIdOption = new Option<int>("--instance-id") { Description = "Instance ID", Required = true };
|
|
var setSourceOption = new Option<string>("--source") { Description = "Source binding canonical name (e.g. 'Pressure' or 'Module.Pressure')", Required = true };
|
|
var setConnectionOption = new Option<string?>("--connection") { Description = "Connection name override (blank = inherited)" };
|
|
var setSourceRefOption = new Option<string?>("--source-ref") { Description = "Source reference override (blank = inherited)" };
|
|
var setFilterOption = new Option<string?>("--filter") { Description = "Condition filter override (blank = inherited)" };
|
|
var setCmd = new Command("set") { Description = "Set (upsert) a native alarm source override on an instance" };
|
|
setCmd.Add(setIdOption); setCmd.Add(setSourceOption); setCmd.Add(setConnectionOption);
|
|
setCmd.Add(setSourceRefOption); setCmd.Add(setFilterOption);
|
|
setCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetInstanceNativeAlarmSourceOverrideCommand(
|
|
result.GetValue(setIdOption),
|
|
result.GetValue(setSourceOption)!,
|
|
result.GetValue(setConnectionOption),
|
|
result.GetValue(setSourceRefOption),
|
|
result.GetValue(setFilterOption)));
|
|
});
|
|
group.Add(setCmd);
|
|
|
|
// clear
|
|
var clearIdOption = new Option<int>("--instance-id") { Description = "Instance ID", Required = true };
|
|
var clearSourceOption = new Option<string>("--source") { Description = "Source binding canonical name", Required = true };
|
|
var clearCmd = new Command("clear") { Description = "Clear a native alarm source override on an instance (revert to inherited)" };
|
|
clearCmd.Add(clearIdOption); clearCmd.Add(clearSourceOption);
|
|
clearCmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new DeleteInstanceNativeAlarmSourceOverrideCommand(
|
|
result.GetValue(clearIdOption),
|
|
result.GetValue(clearSourceOption)!));
|
|
});
|
|
group.Add(clearCmd);
|
|
|
|
return group;
|
|
}
|
|
|
|
private static Command BuildSetArea(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
var areaIdOption = new Option<int?>("--area-id") { Description = "Area ID (omit to clear area assignment)" };
|
|
|
|
var cmd = new Command("set-area") { Description = "Reassign an instance to a different area" };
|
|
cmd.Add(idOption);
|
|
cmd.Add(areaIdOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
var areaId = result.GetValue(areaIdOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new SetInstanceAreaCommand(id, areaId));
|
|
});
|
|
return cmd;
|
|
}
|
|
|
|
private static Command BuildDiff(Option<string> urlOption, Option<string> formatOption, Option<string> usernameOption, Option<string> passwordOption)
|
|
{
|
|
var idOption = new Option<int>("--id") { Description = "Instance ID", Required = true };
|
|
|
|
var cmd = new Command("diff") { Description = "Show deployment diff (deployed vs current template)" };
|
|
cmd.Add(idOption);
|
|
cmd.SetAction(async (ParseResult result) =>
|
|
{
|
|
var id = result.GetValue(idOption);
|
|
return await CommandHelpers.ExecuteCommandAsync(
|
|
result, urlOption, formatOption, usernameOption, passwordOption,
|
|
new GetDeploymentDiffCommand(id));
|
|
});
|
|
return cmd;
|
|
}
|
|
}
|