Class: SensuRunCheck::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu-run-check/cli.rb

Class Method Summary collapse

Class Method Details

.read(arguments = ARGV) ⇒ Hash

Parse CLI arguments using Ruby stdlib ‘optparse`. This method provides SensuRunCheck with process options and can provide users with information, such as the SensuRunCheck version.

Parameters:

  • arguments (Array) (defaults to: ARGV)

    to parse.

Returns:

  • (Hash)

    options



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sensu-run-check/cli.rb', line 11

def self.read(arguments=ARGV)
  options = {}
  optparse = OptionParser.new do |opts|
    opts.on("-h", "--help", "Display this message") do
      puts opts
      exit
    end
    opts.on("-V", "--version", "Display version") do
      puts VERSION
      exit
    end
    opts.on("-c", "--config FILE", "Sensu JSON config FILE") do |file|
      options[:config_file] = file
    end
    opts.on("-d", "--config_dir DIR[,DIR]", "DIR or comma-delimited DIR list for Sensu JSON config files") do |dir|
      options[:config_dirs] = dir.split(",")
    end
    opts.on("-e", "--extension_dir DIR", "DIR for Sensu extensions") do |dir|
      options[:extension_dir] = dir
    end
    opts.on("-r", "--run_check CHECK", "CHECK to run") do |check|
      options[:run_check] = check
    end
    opts.on("-l", "--list_checks", "List all defined checks") do
      options[:list_checks] = true
    end
    opts.on("-R", "--run_all_checks", "Run all defined checks") do
      options[:run_all_checks] = true
    end
  end
  optparse.parse!(arguments)
  options
end