lib/trema/command.rb in trema-0.5.1 vs lib/trema/command.rb in trema-0.6.0

- old
+ new

@@ -1,8 +1,10 @@ require 'English' module Trema + class InvalidLoggingLevel < StandardError; end + # trema command # rubocop:disable ClassLength class Command def self.unix_domain_socket(name = nil, check = false) file_name = name ? "trema.#{name}.ctl" : 'trema.ctl' @@ -19,11 +21,22 @@ # rubocop:disable MethodLength def run(args, options) @args = args @daemon = options[:daemonize] - Controller.logging_level = - options[:verbose] ? ::Logger::DEBUG : ::Logger::INFO + begin + Controller.logging_level = + { debug: ::Logger::DEBUG, + info: ::Logger::INFO, + warn: ::Logger::WARN, + error: ::Logger::ERROR, + fatal: ::Logger::FATAL }.fetch(options[:logging_level].to_sym) + Controller.logging_level = ::Logger::DEBUG if options[:verbose] + rescue KeyError + raise(InvalidLoggingLevel, + "Invalid logging level: #{options[:logging_level]}") + end + $LOAD_PATH.unshift File.expand_path(File.dirname(@args.first)) load @args.first port_number = (options[:port] || Controller::DEFAULT_TCP_PORT).to_i @controller = Controller.create(port_number)