diff options
author | Saku Ytti <saku@ytti.fi> | 2014-04-14 16:28:23 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-04-14 16:28:23 +0300 |
commit | 57a8f4bc04b4f87ad0d7028dcbf29b96d49eaffd (patch) | |
tree | 82567c791b0114e62fa3b978eb2bb95733d6488b /lib/oxidized/cli.rb | |
parent | 1a1794b2b3ac99764852546c550fd7988f84c37b (diff) |
Use 'asetus' for configuration files
Main benefits
a) we get support for system wide configs
b) we don't use symbols in config file, they're confusing to
non-rubyist
Diffstat (limited to 'lib/oxidized/cli.rb')
-rw-r--r-- | lib/oxidized/cli.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb new file mode 100644 index 0000000..720f405 --- /dev/null +++ b/lib/oxidized/cli.rb @@ -0,0 +1,48 @@ +module Oxidized + class CLI + require 'oxidized' + require 'slop' + class CLIError < OxidizedError; end + class NoConfig < CLIError; end + + def run + Process.daemon unless CFG.debug + begin + Oxidized.new + rescue => error + crash error + raise + end + end + + private + + def initialize + if CFGS.system.empty? and CFGS.user.empty? + CFGS.user = CFGS.default + CFGS.save :user + raise NoConfig, 'edit ~/.config/oxidized/config' + end + _args, opts = parse_opts + CFG.debug = true if opts[:debug] + end + + def crash error + open Config::Crash, 'w' do |file| + file.puts '-' * 50 + file.puts Time.now.utc + file.puts error.message + ' [' + error.class.to_s + ']' + file.puts '-' * 50 + file.puts error.backtrace + file.puts '-' * 50 + end + end + + def parse_opts + opts = Slop.new(:help=>true) do + on 'd', 'debug', 'turn on debugging' + end + [opts.parse!, opts] + end + end +end |