feat(cli): typed setpoint flags for template alarm add (serializes trigger-config JSON)

This commit is contained in:
Joseph Doherty
2026-06-07 10:02:51 -04:00
parent 9d7e69056a
commit bbc3804d07
2 changed files with 122 additions and 2 deletions
@@ -226,6 +226,22 @@ public static class TemplateCommands
var lockedOption = new Option<bool>("--locked") { Description = "Lock status" };
lockedOption.DefaultValueFactory = _ => false;
// Typed setpoint flags (alternative to raw --trigger-config; raw wins when both supplied).
var attributeOption = new Option<string?>("--attribute") { Description = "Attribute name the trigger watches (all trigger types except Expression)" };
var matchValueOption = new Option<string?>("--match-value") { Description = "ValueMatch: value to compare against" };
var notEqualsOption = new Option<bool>("--not-equals") { Description = "ValueMatch: match when the value is NOT equal (emits !=)" };
notEqualsOption.DefaultValueFactory = _ => false;
var minOption = new Option<double?>("--min") { Description = "RangeViolation: minimum allowed value" };
var maxOption = new Option<double?>("--max") { Description = "RangeViolation: maximum allowed value" };
var thresholdOption = new Option<double?>("--threshold-per-second") { Description = "RateOfChange: rate threshold per second" };
var windowOption = new Option<double?>("--window-seconds") { Description = "RateOfChange: sliding window in seconds" };
var directionOption = new Option<string?>("--direction") { Description = "RateOfChange: direction (rising|falling|either)" };
var loLoOption = new Option<double?>("--lolo") { Description = "HiLo: low-low setpoint" };
var loOption = new Option<double?>("--lo") { Description = "HiLo: low setpoint" };
var hiOption = new Option<double?>("--hi") { Description = "HiLo: high setpoint" };
var hiHiOption = new Option<double?>("--hihi") { Description = "HiLo: high-high setpoint" };
var expressionOption = new Option<string?>("--expression") { Description = "Expression: boolean trigger expression" };
var addCmd = new Command("add") { Description = "Add an alarm to a template" };
addCmd.Add(templateIdOption);
addCmd.Add(nameOption);
@@ -234,17 +250,41 @@ public static class TemplateCommands
addCmd.Add(descOption);
addCmd.Add(triggerConfigOption);
addCmd.Add(lockedOption);
addCmd.Add(attributeOption);
addCmd.Add(matchValueOption);
addCmd.Add(notEqualsOption);
addCmd.Add(minOption);
addCmd.Add(maxOption);
addCmd.Add(thresholdOption);
addCmd.Add(windowOption);
addCmd.Add(directionOption);
addCmd.Add(loLoOption);
addCmd.Add(loOption);
addCmd.Add(hiOption);
addCmd.Add(hiHiOption);
addCmd.Add(expressionOption);
addCmd.SetAction(async (ParseResult result) =>
{
var triggerType = result.GetValue(triggerTypeOption)!;
var rawConfig = result.GetValue(triggerConfigOption);
var triggerConfig = rawConfig ?? AlarmTriggerConfigJson.Build(
triggerType,
result.GetValue(attributeOption),
result.GetValue(matchValueOption), result.GetValue(notEqualsOption),
result.GetValue(minOption), result.GetValue(maxOption),
result.GetValue(thresholdOption), result.GetValue(windowOption), result.GetValue(directionOption),
result.GetValue(loLoOption), result.GetValue(loOption), result.GetValue(hiOption), result.GetValue(hiHiOption),
result.GetValue(expressionOption));
return await CommandHelpers.ExecuteCommandAsync(
result, urlOption, formatOption, usernameOption, passwordOption,
new AddTemplateAlarmCommand(
result.GetValue(templateIdOption),
result.GetValue(nameOption)!,
result.GetValue(triggerTypeOption)!,
triggerType,
result.GetValue(priorityOption)!,
result.GetValue(descOption),
result.GetValue(triggerConfigOption),
triggerConfig,
result.GetValue(lockedOption)));
});
group.Add(addCmd);