Class: Sym::App::Commands::BaseCommand

Inherits:
Object
  • Object
show all
Includes:
Sym
Defined in:
lib/sym/app/commands/base_command.rb

Constant Summary

Constants included from Sym

BASH_COMPLETION, COMPLETION_FILE, COMPLETION_PATH, DESCRIPTION, ENV_ARGS_VARIABLE_NAME, LOGGER, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ BaseCommand

Returns a new instance of BaseCommand.



53
54
55
# File 'lib/sym/app/commands/base_command.rb', line 53

def initialize(application)
  self.application = application
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



51
52
53
# File 'lib/sym/app/commands/base_command.rb', line 51

def application
  @application
end

Instance Method Details

#add_to_keychain_if_needed(key) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/sym/app/commands/base_command.rb', line 80

def add_to_keychain_if_needed(key)
  if opts[:keychain] && Sym::App.is_osx?
    Sym::App::KeyChain.new(opts[:keychain], opts).add(key)
  else
    key
  end
end

#create_keyObject



76
77
78
# File 'lib/sym/app/commands/base_command.rb', line 76

def create_key
  self.class.create_private_key
end

#encrypt_password_if_needed(key) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/sym/app/commands/base_command.rb', line 88

def encrypt_password_if_needed(key)
  if opts[:password]
    encr_password(key, application.input_handler.new_password)
  else
    key
  end
end

#executeObject



68
69
70
# File 'lib/sym/app/commands/base_command.rb', line 68

def execute
  raise Sym::Errors::AbstractMethodCalled.new(:run)
end

#keyObject



64
65
66
# File 'lib/sym/app/commands/base_command.rb', line 64

def key
  @key ||= application.key
end

#optsObject



57
58
59
# File 'lib/sym/app/commands/base_command.rb', line 57

def opts
  application.opts
end

#opts_hashObject



60
61
62
# File 'lib/sym/app/commands/base_command.rb', line 60

def opts_hash
  application.opts_hash
end

#to_sObject



72
73
74
# File 'lib/sym/app/commands/base_command.rb', line 72

def to_s
  "#{self.class.short_name.to_s.bold.yellow}, with options: #{application.args.argv.join(' ').gsub(/--/, '').bold.green}"
end