class DRbQS::Command::Base
Public Class Methods
exec(argv)
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 9 def self.exec(argv) obj = self.new obj.parse_option(argv) obj.exec end
new(klass = DRbQS::Setting::Base, help_message = nil)
click to toggle source
# 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
Public Instance Methods
exec()
click to toggle source
# 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
setting()
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 20 def setting @opt_setting.setting end
Private Instance Methods
exit_invalid_option()
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 34 def exit_invalid_option Kernel.exit(2) end
exit_normally()
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 24 def exit_normally Kernel.exit(0) end
exit_unusually()
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 29 def exit_unusually Kernel.exit(1) end
option_parser_base(argv, options = {}, &block)
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 39 def option_parser_base(argv, options = {}, &block) @opt_setting.define(options, &block) begin @opt_setting.parse!(argv) rescue DRbQS::Setting::InvalidLogLevel => err $stderr.print err.to_s << "\n\n" << @help_message.to_s exit_invalid_option rescue OptionParser::InvalidOption $stderr.print "error: Invalid Option\n\n" << @help_message.to_s exit_invalid_option rescue OptionParser::InvalidArgument $stderr.print "error: Invalid Argument\n\n" << @help_message.to_s exit_invalid_option end argv end
parse_arguments!()
click to toggle source
# File lib/drbqs/command_line/command_base.rb, line 57 def parse_arguments! setting.parse! end