diff --git a/sgad b/sgad index b022bc09e38f8fd137a42ac594d729312d904ada..cdb2aa2d83027b48682678c059d0d16a61fed63d 100755 --- a/sgad +++ b/sgad @@ -8,10 +8,6 @@ module = nil -- needed for luasocket setting a global variable if Lua 5.2 safer.globals({}, { module = true, loadstring = true, setfenv = true, getfenv = true }) -if os.getenv("HOME") then - io.stderr:write("\27]0;sgad\7") -- set terminal title - io.stderr:write("\27[1;32m".."sgad intializing...".."\27[0m\n") -end local configuration = require("sga.configuration") local application = require("sga.application") @@ -21,21 +17,34 @@ local function script_path() return str:match("(.*)/") or "." end -local config, message = configuration.read(args[1] or os.getenv("SGAD_CONFIG_FILE") or script_path().."/sgad.cfg", args[3]) -if message then +local config, message = configuration.read(args[1] or os.getenv("SGAD_CONFIG_FILE") or script_path().."/sgad.cfg", args[4]) +if message ~= '' and message ~= nil then io.stderr:write(message.."\n") end if not config then os.exit(1) end --- Show config debug -if type(args[2]) == "boolean" and args[2] or ({ [0]=false, [1]=true })[tonumber(args[2])] then +local debug = type(args[2]) == "boolean" and args[2] or ({ [0]=false, [1]=true })[tonumber(args[2])] +local info = type(args[3]) == "boolean" and args[3] or ({ [0]=false, [1]=true })[tonumber(args[3])] + +-- Show config debug/info +if debug or info then local is_readonly = not next(config) and getmetatable(config) local t = is_readonly and getmetatable(config).__index or config - print("============= DEBUG CONFIG =============") - print(util.debug_table(t)) - print("========================================") + if debug then + print("============= DEBUG CONFIG =============") + print(util.debug_table(t)) + print("========================================") + else --info + print(util.debug_table(t)) + os.exit(0) + end +end + +if os.getenv("HOME") then + io.stderr:write("\27]0;sgad\7") -- set terminal title + io.stderr:write("\27[1;32m".."sgad initializing...".."\27[0m\n") end if config.sga_name then diff --git a/sgad.sh b/sgad.sh index aa8c2a620d68b6267927904b237bd54234da7905..889b6fcfd6433de6d67e3485e6331f96f54a22cf 100755 --- a/sgad.sh +++ b/sgad.sh @@ -10,12 +10,14 @@ logfile="logs/sgad_${timestamp}.log" usage() { echo "usage: $0 [configfile] [options]" echo "Available options are:" - echo " --sga_name NAME SGA name to get config from a multiple config file" + echo " --sga_name NAME SGA name to get config from a multiple config file." echo " --debug Enable debug information: show interpreted configuration." + echo " --info Show debug information and exit." } POSITIONAL="" # String para salvar argumentos passados ao comando debug=0 +info=0 while [ $# -gt 0 ] # Percorre todos argumentos do case "$1" in @@ -32,6 +34,10 @@ do debug=1 shift ;; + --info) + info=1 + shift + ;; --*) echo "$0: unrecognized option '$1'" usage @@ -56,4 +62,4 @@ if [ -z ${configfile} ]; then fi eval $(luarocks path --bin) -sgad ${configfile} ${debug} ${sga_name} 2>&1 | tee -a "${logfile}" +sgad ${configfile} ${debug} ${info} ${sga_name} 2>&1 | tee -a "${logfile}"