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.



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

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



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

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

#add_to_keychain_if_needed(key) ⇒ Object



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

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



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

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

#create_keyObject



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

def create_key
  self.class.create_private_key
end

#encrypt_with_password(key) ⇒ Object



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

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

#executeObject



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

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

#to_sObject



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

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