Module: Watchcat::CLI
- Defined in:
- lib/watchcat/cli.rb,
lib/watchcat/cli/config.rb,
lib/watchcat/cli/watcher.rb,
lib/watchcat/cli/action_executor.rb
Defined Under Namespace
Classes: ActionExecutor, Config, Error, Watcher
Class Method Summary
collapse
Class Method Details
.parse(argv) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/watchcat/cli.rb', line 25
def parse(argv)
options = { config: 'watchcat.yml' }
OptionParser.new do |opts|
opts.banner = "Usage: watchcat [options]"
opts.on("-C", "--config PATH", "Path to the config file. Default is 'watchcat.yml'.") do |v|
options[:config] = v
end
opts.on("--init PATH", "Generate a template config file at the specified path") do |v|
options[:init] = v
end
opts.on("-h", "--help", "Show this help message") do
puts opts
exit
end
end.parse!(argv)
if !options[:init] && options[:config].nil?
raise OptionParser::MissingArgument.new("-C")
end
options
end
|
.start(argv) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/watchcat/cli.rb', line 10
def start(argv)
options = parse(argv)
if options[:init]
Config.generate_template(options[:init])
return
end
config = Config.load(options[:config])
watcher = Watcher.new(config)
watcher.start
rescue => e
raise Error, "Failed to start Watchcat: #{e.message}"
end
|