class Crowbar::Client::App::Base
A base class that provides helper for the wrappers
Public Class Methods
Properly print an error on invalid command
@param command [String] the command that failed @param error [StandardError] the error class @param args [Array] the arguments that failed @param arity [Integer] the number of arguments
# File lib/crowbar/client/app/base.rb, line 129 def handle_argument_error(command, error, args, arity) $stderr.puts("Usage: #{banner(command)}") exit(2) end
Initialize the Thor command
@param args [Array] the arguments @param local_options [Hash] the local options @param config [Hash] the configuration @return [Crowbar::Client::App::Base]
# File lib/crowbar/client/app/base.rb, line 35 def initialize(args = [], local_options = {}, config = {}) super Config.configure( options.slice( :alias, :username, :password, :server, :verify_ssl, :timeout, :anonymous, :apiversion, :debug ) ) end
Public Instance Methods
General errors to catch properly
@param error [StandardError] the error to catch @raise [StandardError] only raised if uncatchable
# File lib/crowbar/client/app/base.rb, line 106 def catch_errors(error) case error when SimpleCatchableError err error.message, 1 when Errno::ECONNREFUSED err "Connection to server refused", 1 when SocketError err "Unknown server to connect to", 1 else raise error end end
Standard parameters for commands
@param args [Hash] the arguments to inject @return [Array]
# File lib/crowbar/client/app/base.rb, line 90 def command_params(args = {}) [ $stdin, $stdout, $stderr, options, args ] end
Print a message to STDERR
@param message [String] the message to print @param exit_code [Integer] the exit code to use
# File lib/crowbar/client/app/base.rb, line 71 def err(message, exit_code = nil) case provide_format when :json $stderr.puts JSON.pretty_generate( error: message ) else $stderr.puts message end exit(exit_code) unless exit_code.nil? end
Print a message to STDOUT
@param message [String] the message to print
# File lib/crowbar/client/app/base.rb, line 61 def say(message) $stdout.puts message end