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

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

Constant Summary

Constants included from Sym

DESCRIPTION, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sym

config, default_key, default_key?, default_key_file

Constructor Details

#initialize(application) ⇒ BaseCommand

Returns a new instance of BaseCommand.



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

def initialize(application)
  self.application = application
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



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

def application
  @application
end

Instance Method Details

#add_password_to_the_cache(encrypted_key, password) ⇒ Object



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

def add_password_to_the_cache(encrypted_key, password)
  self.application.password_cache[encrypted_key] = password
end

#add_to_keychain_if_needed(key) ⇒ Object



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

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

#contentObject



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

def content
  @content ||= (opts[:string] || (opts[:file].eql?('-') ? stdin.read : ::File.read(opts[:file]).chomp))
end

#create_keyObject



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

def create_key
  self.class.create_private_key
end

#encrypt_with_password(key) ⇒ Object



84
85
86
87
# File 'lib/sym/app/commands/base_command.rb', line 84

def encrypt_with_password(key)
  password = application.input_handler.new_password
  return encr_password(key, password), password
end

#executeObject



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

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

#to_sObject



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

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