Skip to content

Commit a9eb5cf

Browse files
committed
Add verbose switch
1 parent aa08cb7 commit a9eb5cf

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

bin/xify

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
44

55
require 'xify'
66

7-
Xify.run ARGV
7+
Xify.run

lib/xify.rb

+24-8
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,36 @@
99
require 'xify/output/rocket_chat'
1010

1111
class Xify
12-
def self.run(args)
12+
@verbose = false
13+
14+
def self.run
1315
working_dir = "#{ENV['HOME']}/.xify"
1416
Dir.mkdir working_dir rescue Errno::EEXIST
15-
1617
config_file = "#{working_dir}/config.yml"
17-
if args.first == '-c'
18-
args.shift
19-
config_file = args.shift
18+
files = []
19+
20+
while arg = ARGV.shift do
21+
case arg
22+
when '-c', '--config'
23+
config_file = ARGV.shift
24+
when '-v', '--verbose'
25+
@verbose = true
26+
else
27+
files << arg
28+
end
2029
end
2130

22-
puts "Loading config from #{config_file}"
31+
ARGV.unshift(*files)
32+
33+
debug "Loading config from #{config_file}"
2334
config = YAML::load_file config_file
2435

2536
config.keys.each do |section|
26-
ns = section[0...-1].capitalize
37+
type = section[0...-1]
2738
config[section].map! do |handler|
2839
next unless handler['enabled']
29-
Object.const_get("#{ns}::#{handler['class']}").new handler
40+
debug "Setting up #{handler['class']} as #{type}"
41+
Object.const_get("#{type.capitalize}::#{handler['class']}").new handler
3042
end.compact!
3143
end
3244

@@ -44,4 +56,8 @@ def self.run(args)
4456

4557
Rufus::Scheduler.singleton.join
4658
end
59+
60+
def self.debug(str)
61+
puts str if @verbose
62+
end
4763
end

0 commit comments

Comments
 (0)