<commit_before>local Configuration = require "cosy.configuration"
local I18n          = require "cosy.i18n"
local Value         = require "cosy.value"
local Cli           = require "cliargs"
local Colors        = require "ansicolors"
local Websocket     = require "websocket"

Configuration.load {
  "cosy",
  "cosy.daemon",
  "cosy.server",
}

local i18n   = I18n.load {
  "cosy.commands",
  "cosy.daemon",
}
i18n._locale = Configuration.cli.default_locale._

if _G.nocolor then
  Colors = function (s)
    return s:gsub ("(%%{(.-)})", "")
  end
end

local function read (filename)
  local file = io.open (filename, "r")
  if not file then
    return nil
  end
  local data = file:read "*all"
  file:close ()
  return Value.decode (data)
end

-- http://lua.2524044.n2.nabble.com/Reading-passwords-in-a-console-application-td6641037.html
local function getpassword ()
  local stty_ret = os.execute ("stty -echo 2>/dev/null")
  if stty_ret ~= 0 then
    io.write("\027[08m") -- ANSI 'hidden' text attribute 
  end 
  local ok, pass = pcall (io.read, "*l")
  if stty_ret == 0 then
    os.execute("stty sane")
  else 
    io.write("\027[00m")
  end 
  io.write("\n")
  os.execute("stty sane") 
  if ok then 
    return pass
  end 
end

local function show_status (result)
  assert (type (result) == "table")
  if result.success then
    if type (result.response) ~= "table" then
      result.response = { message = result.response }
    end
    print (Colors ("%{black greenbg}" .. i18n ["success"] % {}),
           Colors ("%{green blackbg}" .. (result.response.message ~= nil and tostring (result.response.message) or "")))
  elseif result.error then
    print (Colors ("%{black redbg}" .. i18n ["failure"] % {}),
           Colors ("%{red blackbg}" .. (result.error.message ~= nil and tostring (result.error.message) or "")))
  end
  return result
end

local Commands = {}
local Prepares = {}
local Options  = {}
local Results  = {}

function Options.set (part, name, oftype, description)
  if name == "locale" then<commit_msg>Show error messages in cli.<commit_after>local Configuration = require "cosy.configuration"
local I18n          = require "cosy.i18n"
local Value         = require "cosy.value"
local Cli           = require "cliargs"
local Colors        = require "ansicolors"
local Websocket     = require "websocket"

Configuration.load {
  "cosy",
  "cosy.daemon",
  "cosy.server",
}

local i18n   = I18n.load {
  "cosy.commands",
  "cosy.daemon",
}
i18n._locale = Configuration.cli.default_locale._

if _G.nocolor then
  Colors = function (s)
    return s:gsub ("(%%{(.-)})", "")
  end
end

local function read (filename)
  local file = io.open (filename, "r")
  if not file then
    return nil
  end
  local data = file:read "*all"
  file:close ()
  return Value.decode (data)
end

-- http://lua.2524044.n2.nabble.com/Reading-passwords-in-a-console-application-td6641037.html
local function getpassword ()
  local stty_ret = os.execute ("stty -echo 2>/dev/null")
  if stty_ret ~= 0 then
    io.write("\027[08m") -- ANSI 'hidden' text attribute 
  end 
  local ok, pass = pcall (io.read, "*l")
  if stty_ret == 0 then
    os.execute("stty sane")
  else 
    io.write("\027[00m")
  end 
  io.write("\n")
  os.execute("stty sane") 
  if ok then 
    return pass
  end 
end

local function show_status (result)
  assert (type (result) == "table")
  if result.success then
    if type (result.response) ~= "table" then
      result.response = { message = result.response }
    end
    print (Colors ("%{black greenbg}" .. i18n ["success"] % {}),
           Colors ("%{green blackbg}" .. (result.response.message ~= nil and tostring (result.response.message) or "")))
  elseif result.error then
    print (Colors ("%{black redbg}" .. i18n ["failure"] % {}),
           Colors ("%{red blackbg}" .. (result.error.message ~= nil and tostring (result.error.message) or "")))
    if result.error._ == "check:error" then
      local max = 0
      for i = 1, #result.error.reasons do
        local reason = result.error.reasons [i]
        max = math.max (max, #reason.parameter)
      end
      for i = 1, #result.error.reasons do
        local reason    = result.error.reasons [i]
        local parameter = reason.parameter
        local message   = reason.message
        local space = ""
        for _ = #parameter, max+3 do
          space = space .. " "
        end
        space = space .. " => "
        print (Colors ("%{black redbg}" .. tostring (parameter)) ..
               Colors ("%{reset}" .. space) ..
               Colors ("%{red blackbg}" .. tostring (message)))
      end
    end
  end
  return result
end

local Commands = {}
local Prepares = {}
local Options  = {}
local Results  = {}

function Options.set (part, name, oftype, description)
  if name == "locale" then
{'fraction_non_alphanumeric': 0.14521176716044232, 'fraction_numerical': 0.01836010849155018, 'mean_word_length': 2.7423887587822016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '77156', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1593, 'n_words': 446}