Class: Dribbled::CLI

Inherits:
Object
  • Object
show all
Includes:
Senedsa
Defined in:
lib/dribbled/cli.rb

Constant Summary collapse

COMMANDS =
%w(show check snap watch)
COMPONENTS =
%w(resources)
DEFAULT_CONFIG_FILE =
File.join(ENV['HOME'],"/.senedsa/config")
STATUS =
{
  :ok       =>  OpenStruct.new({ :num => 0, :str => "OK",       }),
  :warning  =>  OpenStruct.new({ :num => 1, :str => "WARNING",  }),
  :critical =>  OpenStruct.new({ :num => 2, :str => "CRITICAL", }),
  :unknown  =>  OpenStruct.new({ :num => 3, :str => "UNKNOWN"   })
}

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CLI

Returns a new instance of CLI.



25
26
27
28
29
30
31
32
33
# File 'lib/dribbled/cli.rb', line 25

def initialize(arguments)
  @arguments = arguments
  @whoami = File.basename($PROGRAM_NAME).to_sym

  @global_options = { :debug => false, :drbdadm => 'drbdadm', :xmldump => nil, :procdrbd => '/proc/drbd', :hostname => nil }
  @action_options = { :monitor => :nagios, :mode => :active, :suffix => nil, :directory => '/tmp' }
  @action_arguments = {}
  @action = nil
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dribbled/cli.rb', line 35

def run
  begin
    parsed_options?

    @log = Dribbled::Logger.instance.log
    @log.level = Log4r::INFO unless @global_options[:debug]
    @global_options[:log] = @log

    config_options?
    arguments_valid?
    options_valid?
    process_options
    process_arguments
    process_command

  rescue => e
    if @global_options[:debug]
      output_message "#{e.message}\n  #{e.backtrace.join("\n  ")}",3
    else
      output_message e.message,3
    end
  end
end