Sha256: 5802d6173ef34605022834f2d4fe3edfe2850bff0d3858055aa380da143d5532

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require_relative 'command'
require 'shhh/app/keychain'
module Shhh
  module App
    module Commands
      class GenerateKey < Command
        include Shhh

        required_options :generate

        def run
          retries         ||= 0
          new_private_key = self.class.create_private_key

          if opts[:password]
            new_private_key = encr_password(new_private_key,
                                            Shhh::App::Input::Handler.new_password)
          end

          clipboard_copy(new_private_key) if opts[:copy]

          if opts[:keychain] && Shhh::App.is_osx?
            Shhh::App::KeyChain.new(opts[:keychain]).add(new_private_key)
          end

          new_private_key
        rescue Shhh::Errors::PasswordsDontMatch, Shhh::Errors::PasswordTooShort => e
          STDERR.puts e.message.bold
          retry if (retries += 1) < 3
        end

        private

        def clipboard_copy(key)
          require 'clipboard'
          Clipboard.copy(key)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shhh-1.3.0 lib/shhh/app/commands/generate_key.rb