class EYAML::CLI

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/eyaml/cli.rb, line 63
def self.exit_on_failure?
  true
end

Public Instance Methods

decrypt(file) click to toggle source
# File lib/eyaml/cli.rb, line 21
def decrypt(file)
  file_path = Pathname.new(file)
  unless file_path.exist?
    puts "#{file} doesn't exist"
    return
  end

  key_options = if options.fetch(:"key-from-stdin")
    # Read key from STDIN
    {private_key: $stdin.gets}
  else
    {keydir: options.fetch(:keydir, nil)}
  end

  eyaml = EYAML.decrypt_file(file, **key_options)

  if options.has_key?("output")
    output_file = Pathname.new(options.fetch(:output))
    File.write(output_file, eyaml)
    return
  end

  puts eyaml
end
encrypt(*files) click to toggle source
# File lib/eyaml/cli.rb, line 6
def encrypt(*files)
  files.each do |file|
    file_path = Pathname.new(file)
    next unless file_path.exist?

    bytes_written = EYAML.encrypt_file_in_place(file_path)

    puts "Wrote #{bytes_written} bytes to #{file_path}."
  end
end
keygen() click to toggle source
# File lib/eyaml/cli.rb, line 49
def keygen
  public_key, private_key = EYAML.generate_keypair(
    save: options.fetch(:write),
    keydir: options.fetch(:keydir, nil)
  )

  puts "Public Key: #{public_key}"
  puts "Private Key: #{private_key}" unless options.fetch(:write)
end