From 76417cefad15065f74a1419127e44482708d6326 Mon Sep 17 00:00:00 2001 From: Iury Date: Fri, 27 Oct 2023 18:51:54 -0300 Subject: [PATCH] Created rename_unique_agent method --- extensions/expression.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/extensions/expression.lua b/extensions/expression.lua index 097b9d5..77e51c9 100644 --- a/extensions/expression.lua +++ b/extensions/expression.lua @@ -403,3 +403,33 @@ end -- end -- return self:select_stage(self:last_stage()); -- end + +function Expression.rename_unique_agent(self, agent_name, substitute_name) + local tag = "REMANE_UNIT_AGENT"; + + if not self:loaded() then + warning(tag .. ": null at " .. PSR.source_line(2)); + return self; + end + + if agent_name == nil then + warning(tag .. ": agent name must not be nil"); + return self; + end + + if substitute_name == nil then + warning(tag .. ": substite name must not be nil"); + return self; + end + + local data_selected_agent = self:select_agent(agent_name):rename_agents({ substitute_name }); + + if not data_selected_agent:loaded() then + warning(tag .. ": " .. agent_name .. " not found"); + return self; + end + + local data_remoded_agent = self:remove_agent(agent_name); + + return concatenate(data_selected_agent, data_remoded_agent); +end