Class: Sym::App::Commands::BaseCommand
- Inherits:
-
Object
- Object
- Sym::App::Commands::BaseCommand
show all
- Includes:
- Sym
- Defined in:
- lib/sym/app/commands/base_command.rb
Direct Known Subclasses
BashCompletion, Decrypt, Encrypt, GenerateKey, KeychainAddKey, OpenEditor, PasswordProtectKey, PrintKey, ShowExamples, ShowHelp, ShowVersion
Constant Summary
Constants included
from Sym
BASH_COMPLETION, COMPLETION_FILE, COMPLETION_PATH, DESCRIPTION, ENV_ARGS_VARIABLE_NAME, LOGGER, NIL_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
#application ⇒ Object
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
84
85
86
87
88
89
90
|
# File 'lib/sym/app/commands/base_command.rb', line 84
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
|
72
73
74
|
# File 'lib/sym/app/commands/base_command.rb', line 72
def content
@content ||= (opts[:string] || (opts[:file].eql?('-') ? STDIN.read : File.read(opts[:file])))
end
|
#create_key ⇒ Object
80
81
82
|
# File 'lib/sym/app/commands/base_command.rb', line 80
def create_key
self.class.create_private_key
end
|
#encrypt_password_if_needed(key) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/sym/app/commands/base_command.rb', line 92
def encrypt_password_if_needed(key)
if opts[:password]
encr_password(key, application.input_handler.new_password)
else
key
end
end
|
64
65
66
|
# File 'lib/sym/app/commands/base_command.rb', line 64
def key
@key ||= application.key
end
|
57
58
59
|
# File 'lib/sym/app/commands/base_command.rb', line 57
def opts
application.opts
end
|
#opts_hash ⇒ Object
60
61
62
|
# File 'lib/sym/app/commands/base_command.rb', line 60
def opts_hash
application.opts_hash
end
|
76
77
78
|
# File 'lib/sym/app/commands/base_command.rb', line 76
def to_s
"#{self.class.short_name.to_s.bold.yellow}, with options: #{application.args.argv.join(' ').gsub(/--/, '').bold.green}"
end
|