Class: DRbQS::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Argument, Misc
Defined in:
lib/drbqs/command_line/command_base.rb

Direct Known Subclasses

Execute, Manage, Node, SSH, Server

Constant Summary collapse

@@command_name =
File.basename($PROGRAM_NAME)

Constants included from Misc

Misc::STRINGS_FOR_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Argument

check_argument_size, split_arguments

Methods included from Misc

create_logger, create_uri, output_error, process_running_normally?, random_key, time_to_history_string, time_to_history_string2, uri_drbunix

Constructor Details

#initialize(klass = DRbQS::Setting::Base, help_message = nil) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/drbqs/command_line/command_base.rb', line 15

def initialize(klass =  DRbQS::Setting::Base, help_message = nil)
  @help_message = help_message
  @opt_setting = DRbQS::Command::OptionSetting.new(@help_message, klass.new)
end

Class Method Details

.exec(argv) ⇒ Object



9
10
11
12
13
# File 'lib/drbqs/command_line/command_base.rb', line 9

def self.exec(argv)
  obj = self.new
  obj.parse_option(argv)
  obj.exec
end

Instance Method Details

#execObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/drbqs/command_line/command_base.rb', line 62

def exec
  begin
    parse_arguments!
    setting.exec($stdout)
    exit_normally
  rescue DRb::DRbConnError => err
    $stderr.puts "error: Can not connect. #{err.to_s}"
    exit_unusually
  rescue DRbQS::Setting::InvalidArgument => err
    mes = "error: Invalid command argument. #{err.to_s}\n\n" << @help_message.to_s
    $stderr.print mes
    exit_invalid_option
  rescue => err
    output_error(err, $stderr)
    exit_unusually
  end
end

#settingObject



20
21
22
# File 'lib/drbqs/command_line/command_base.rb', line 20

def setting
  @opt_setting.setting
end