diff -r cda6a004ff79 -r f1901c9de891 clix.lua --- a/clix.lua Sat May 29 20:58:27 2010 +0100 +++ b/clix.lua Sat May 29 21:13:27 2010 +0100 @@ -12,9 +12,7 @@ short_opts = { v = "verbose", q = "quiet", t = "to", f = "from", e = "type", a = "account", p = "password", r = "resource", o = "presence", c = "chatroom" } -local command = arg[1]; - -if not command then +if #arg < 1 then print("Command Line XMPP, available commands:"); for module in pairs(package.preload) do if module:match("^clix%.") then @@ -26,30 +24,10 @@ return 0; end -local ok, m = pcall(require, "clix."..command); -if not ok then - local is_debug; - for i=1,#arg do - if arg[i] == "--debug" then - is_debug = true; break; - end - end - print("Error running command '"..command..(is_debug and "" or "' (run with --debug to see full error)")); - if is_debug then - print(m); - end - return 1; -end - -if type(m) ~= "function" then - print(command.." is not a valid command"); - return 1; -end - local accounts = { default = {} }; local current_account; -local config_path = (os.getenv("XDG_CONFIG_HOME") or (os.getenv("HOME").."/.config"); +local config_path = (os.getenv("XDG_CONFIG_HOME") or (os.getenv("HOME").."/.config")); local config_file, err = io.open(config_path.."/.clixrc") or io.open(config_path.."/.clix"); if not config_file then @@ -152,5 +130,27 @@ table.remove(arg, n); end +local command = arg[1]; + +local ok, m = pcall(require, "clix."..command); +if not ok then + local is_debug; + for i=1,#arg do + if arg[i] == "--debug" then + is_debug = true; break; + end + end + print("Error running command '"..command..(is_debug and "" or "' (run with --debug to see full error)")); + if is_debug then + print(m); + end + return 1; +end + +if type(m) ~= "function" then + print(command.." is not a valid command"); + return 1; +end + return m(opts, arg) or 0;