class Sidewatch::CLI
Attributes
config_file[RW]
options[RW]
working_dir[RW]
Public Class Methods
new(pwd = Dir.pwd)
click to toggle source
# File lib/sidewatch/cli.rb, line 9 def initialize(pwd = Dir.pwd) self.working_dir = pwd parse_options parse_config setup_logger end
Public Instance Methods
run()
click to toggle source
# File lib/sidewatch/cli.rb, line 16 def run Sidewatch::Daemon.new(Sidewatch.config).run end
Private Instance Methods
drop_daemons_args(args)
click to toggle source
# File lib/sidewatch/cli.rb, line 24 def drop_daemons_args(args) args = args.drop_while{|arg| arg != "--"} args.drop(1) end
parse_config()
click to toggle source
# File lib/sidewatch/cli.rb, line 45 def parse_config self.config_file = options.fetch(:config){ "/etc/sidewatch.yml" } self.config_file = File.expand_path(config_file, working_dir) if File.exists?(config_file) config = YAML.load(ERB.new(IO.read(config_file)).result) config.merge(options) Sidewatch.config = config.symbolize_keys end end
parse_options(args = ARGV)
click to toggle source
# File lib/sidewatch/cli.rb, line 29 def parse_options(args = ARGV) args = drop_daemons_args(args) options = {} parser = OptionParser.new do |opts| opts.banner = "Usage: #{__FILE__} [start|stop|run] (-- [options])" opts.on("-c", "--config PATH", "path to YAML Config file") do |file| options[:config] = file end opts.on("-l", "--logfile PATH", "path to writeable logfile") do |file| options[:logfile] = file end end parser.parse(args) self.options = options end
setup_logger()
click to toggle source
# File lib/sidewatch/cli.rb, line 55 def setup_logger logfile = if options[:logfile] File.expand_path(options[:logfile], working_dir) elsif Sidewatch.config[:logfile] File.expand_path(Sidewatch.config[:logfile], File.dirname(config_file)) end Sidewatch.logger = Logger.new(logfile) if logfile end