lib/shhh/application.rb in shhh-1.6.5 vs lib/shhh/application.rb in shhh-1.7.0

- old
+ new

@@ -1,23 +1,28 @@ -require 'shhh' require 'colored2' +require 'shhh' +require_dir 'shhh/app' + module Shhh class Application attr_accessor :opts, :opts_hash, :args, :action, :key, :input_handler, :key_handler, - :result + :result, + :password_cache def initialize(opts) self.opts = opts self.opts_hash = opts.respond_to?(:to_hash) ? opts.to_hash : opts self.args = ::Shhh::App::Args.new(opts_hash) + + initialize_password_cache initialize_input_handler initialize_key_handler initialize_action end @@ -28,12 +33,13 @@ :decr end end def execute! - if args.do_options_require_key? || args.do_options_specify_key? - self.key = Shhh::App::PrivateKey::Handler.new(opts, input_handler).key + if !args.generate_key? && + (args.require_key? || args.specify_key?) + self.key = Shhh::App::PrivateKey::Handler.new(opts, input_handler, password_cache).key raise Shhh::Errors::NoPrivateKeyFound.new('Private key is required') unless self.key end unless command raise Shhh::Errors::InsufficientOptionsError.new( @@ -60,25 +66,49 @@ end def command @command_class ||= Shhh::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class + @command end def editor - ENV['EDITOR'] || '/bin/vi' + editors_to_try.find { |editor| File.exist?(editor) } end + def editors_to_try + [ + ENV['EDITOR'], + '/usr/bin/vim', + '/usr/local/bin/vim', + '/bin/vim', + '/sbin/vim', + '/usr/sbin/vim', + '/usr/bin/vi', + '/usr/local/bin/vi', + '/bin/vi', + '/sbin/vi' + ] + end + def error(hash) hash end def initialize_input_handler(handler = ::Shhh::App::Input::Handler.new) self.input_handler = handler end def initialize_key_handler - self.key_handler = ::Shhh::App::PrivateKey::Handler.new(self.opts, input_handler) + self.key_handler = ::Shhh::App::PrivateKey::Handler.new(self.opts, input_handler, password_cache) end + def initialize_password_cache + args = {} + args[:provider] = Coin + args[:timeout] = opts[:password_timeout].to_i if opts[:password_timeout] + args[:enabled] = false if opts[:no_password_cache] + + self.password_cache = Shhh::App::Password::Cache.instance.configure(args) + end end end