diff --git a/src/ZB.MOM.WW.ScadaBridge.CLI/Commands/CachedCallCommands.cs b/src/ZB.MOM.WW.ScadaBridge.CLI/Commands/CachedCallCommands.cs index 3d7cc993..70feb5ef 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CLI/Commands/CachedCallCommands.cs +++ b/src/ZB.MOM.WW.ScadaBridge.CLI/Commands/CachedCallCommands.cs @@ -15,14 +15,11 @@ public static class CachedCallCommands { // Options are static so the parsed values can be read back from both SetAction // and the internal BuildRetryCommand / BuildDiscardCommand helpers (used by tests). - private static readonly Option RetrySiteIdOption = + // A single shared instance per option is safe: retry and discard are sibling + // sub-commands and cannot be invoked simultaneously. + private static readonly Option SiteIdOption = new("--site-id") { Description = "Site identifier of the parked operation", Required = true }; - private static readonly Option RetryMessageIdOption = - new("--tracked-operation-id") { Description = "Tracked operation ID (MessageId) of the parked cached call", Required = true }; - - private static readonly Option DiscardSiteIdOption = - new("--site-id") { Description = "Site identifier of the parked operation", Required = true }; - private static readonly Option DiscardMessageIdOption = + private static readonly Option MessageIdOption = new("--tracked-operation-id") { Description = "Tracked operation ID (MessageId) of the parked cached call", Required = true }; /// @@ -46,24 +43,28 @@ public static class CachedCallCommands private static Command BuildRetry(Option urlOption, Option formatOption, Option usernameOption, Option passwordOption) { var cmd = new Command("retry") { Description = "Retry a parked cached-call operation" }; - cmd.Add(RetrySiteIdOption); - cmd.Add(RetryMessageIdOption); + cmd.Add(SiteIdOption); + cmd.Add(MessageIdOption); cmd.SetAction(async (ParseResult result) => - await CommandHelpers.ExecuteCommandAsync( + { + return await CommandHelpers.ExecuteCommandAsync( result, urlOption, formatOption, usernameOption, passwordOption, - BuildRetryCommand(result))); + BuildRetryCommand(result)); + }); return cmd; } private static Command BuildDiscard(Option urlOption, Option formatOption, Option usernameOption, Option passwordOption) { var cmd = new Command("discard") { Description = "Discard a parked cached-call operation" }; - cmd.Add(DiscardSiteIdOption); - cmd.Add(DiscardMessageIdOption); + cmd.Add(SiteIdOption); + cmd.Add(MessageIdOption); cmd.SetAction(async (ParseResult result) => - await CommandHelpers.ExecuteCommandAsync( + { + return await CommandHelpers.ExecuteCommandAsync( result, urlOption, formatOption, usernameOption, passwordOption, - BuildDiscardCommand(result))); + BuildDiscardCommand(result)); + }); return cmd; } @@ -76,8 +77,8 @@ public static class CachedCallCommands /// A populated from the parsed result. internal static RetryParkedMessageCommand BuildRetryCommand(ParseResult result) { - var siteId = result.GetValue(RetrySiteIdOption)!; - var messageId = result.GetValue(RetryMessageIdOption)!; + var siteId = result.GetValue(SiteIdOption)!; + var messageId = result.GetValue(MessageIdOption)!; return new RetryParkedMessageCommand(siteId, messageId); } @@ -90,8 +91,8 @@ public static class CachedCallCommands /// A populated from the parsed result. internal static DiscardParkedMessageCommand BuildDiscardCommand(ParseResult result) { - var siteId = result.GetValue(DiscardSiteIdOption)!; - var messageId = result.GetValue(DiscardMessageIdOption)!; + var siteId = result.GetValue(SiteIdOption)!; + var messageId = result.GetValue(MessageIdOption)!; return new DiscardParkedMessageCommand(siteId, messageId); } }