Class: SysWatch::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/syswatch/cli.rb

Overview

Handles command line interface

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ CLI

Initialize a new system watcher

Parameters:

  • argv (Hash)

    the command line parameters hash (usually ‘ARGV`).

  • env (Hash)

    the environment variables hash (usually ‘ENV`).



12
13
14
15
16
# File 'lib/syswatch/cli.rb', line 12

def initialize(argv, env)
	parse_options! argv

	@runner = Runner.new @options
end

Instance Method Details

#parse_options!(args) ⇒ Object

Parse the command line options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/syswatch/cli.rb', line 19

def parse_options!(args)
	@options = {}
	opts = ::OptionParser.new do |opts|
		opts.banner = "Usage: syswatch [options]\n\n  Options:"

		opts.on("-f", "--foreground", "Do not daemonize, just run in foreground.") do |f|
			@options[:foreground] = f
		end

		opts.on("-v", "--verbose", "Be verbose, print out some messages.") do |v|
			@options[:verbose] = v
		end

		opts.on("-t", "--test", "Test notifications.") do |t|
			@options[:test] = t
		end

		opts.on("-c", "--config [FILE]", "Use a specific config file, instead of `#{SysWatch::DEFAULTS[:config]}`") do |config|
			@options[:config] = config
		end
	end
	opts.parse! args
end