class Forward::Command::Base
Attributes
args[RW]
options[RW]
Public Class Methods
new(options = {}, args = [])
click to toggle source
# File lib/forward/command/base.rb, line 14 def initialize(options = {}, args = []) @opts = options @options = options.to_hash @args = args logger.debug "[CLI] options: #{@options.inspect}" logger.debug "[CLI] args: #{@args.inspect}" end
run(command, options = {}, args = [])
click to toggle source
# File lib/forward/command/base.rb, line 9 def self.run(command, options = {}, args = []) Forward.logger.debug "[CLI] running `#{command}'" new(options, args).send(command) end
Private Instance Methods
ask_for_credentials(email = nil)
click to toggle source
# File lib/forward/command/base.rb, line 32 def ask_for_credentials(email = nil) if email.nil? || email !~ EMAIL_REGEX puts "Forward requires an account on #{HighLine.color('forwardhq.com', :underline)}" puts "Enter your email and password" email = ask('email: ').chomp end password = ask('password: ') { |q| q.echo = false }.chomp [email, password] end
client() { || ... }
click to toggle source
# File lib/forward/command/base.rb, line 24 def client(&block) EM.run { yield Signal.trap('INT') { EM.stop; exit } Signal.trap('TERM') { EM.stop; exit } } end
print_help_and_exit!()
click to toggle source
# File lib/forward/command/base.rb, line 44 def print_help_and_exit! puts @opts exit end
validate(*validators)
click to toggle source
# File lib/forward/command/base.rb, line 49 def validate(*validators) validators.each do |validator| validator = "validate_#{validator}" if respond_to?(validator, true) send(validator) else raise UnknownValidator, "Unable to find validator `#{validator}' in #{self.class.name}" end end end