<commit_before>-- Use of this source code is governed by the Apache 2.0 license; see COPYING.
module(..., package.seeall)

local common = require("program.config.common")

local function usage(exit_code)
   print(require("program.config.set_alarm_operator_state.README_inc"))
   main.exit(exit_code)
end

local function parse_args (args)
   local function parse_alarm_key (key)
      local t = {}
      for each in key:gmatch("([^,]+)") do
         table.insert(t, each)
      end
      return {resource=t[1], alarm_type_id=t[2], alarm_type_qualifier=t[3] or ''}
   end
   if #args < 3 or #args > 4 then usage(1) end
   local ret = {
      key = parse_alarm_key(args[2]),
      state = args[3],
      text = args[4] or '',
   }
   for i=2,#args do
      table.remove(args, #args)
   end
   return ret
end

function run(args)
   local l_args = parse_args(args)<commit_msg>Rework argument parsing<commit_after>-- Use of this source code is governed by the Apache 2.0 license; see COPYING.
module(..., package.seeall)

local common = require("program.config.common")

local function usage(exit_code)
   print(require("program.config.set_alarm_operator_state.README_inc"))
   main.exit(exit_code)
end

local function parse_args (args)
   if #args < 4 or #args > 5 then usage(1) end
   local alarm_type_id, alarm_type_qualifier = (args[3]):match("([%w]+)/([%w]+)")
   if not alarm_type_id then
      alarm_type_id, alarm_type_qualifier = args[3], ''
   end
   local ret = {
      key = {
         resource = args[2],
         alarm_type_id = alarm_type_id,
         alarm_type_qualifier = alarm_type_qualifier,
      },
      state = args[4],
      text = args[5] or '',
   }
   -- Remove all arguments except first one.
   for i=2,#args do
      table.remove(args, #args)
   end
   return ret
end

function run(args)
   local l_args = parse_args(args)
{'fraction_non_alphanumeric': 0.12344342176502436, 'fraction_numerical': 0.01245262587980509, 'mean_word_length': 3.2288329519450802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2278511', 'n_tokens_mistral': 639, 'n_tokens_neox': 629, 'n_words': 168}