Sha256: 98ee9fb0a0511a5d8999b1edd987a4f75c9f0a7450f13e1d15a9e75c32a27cac

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby

require_relative "../lib/2pass"

def help_message
  puts <<~HELP
    Usage:
      2pass add <vault_name> <id> <value>   - Add new secret
      2pass get <vault_name> <id>           - Get content by ID from the specified vault
      2pass list <vault_name>               - List the content of the specified vault
      2pass link <vault_name> <target_path> - Create a symlink for an existing vault. Useful when the vault is stored in a synced place (iCloud, Dropbox, etc.)
      2pass -h                              - Display this help message
  HELP
end

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: 2pass [options]"

  opts.on("-h", "--help", "Display this help message") do
    options[:help] = true
  end
  opts.on("-v", "--version", "Display the version") do
    options[:version] = true
  end
end.parse!

if options[:help]
  help_message
  exit
end

if options[:version]
  puts TwoPass::VERSION
  exit
end

if ARGV.length < 2
  help_message
  exit(1)
end

command, vault_name, *args = ARGV

begin
  case command
  when "get"
    if args.length < 1
      help_message
      exit(1)
    end
    id = args[0]
    puts TwoPass.get_secret(vault_name, id)
  when "add"
    if args.length != 2
      help_message
      exit(1)
    end
    TwoPass.add_secret(vault_name, args[0], args[1])
  when "list"
    puts TwoPass.list_content(vault_name)
  when "link"
    if args.length < 1
      help_message
      exit(1)
    end
    target_path = args[0]
    TwoPass.create_symlink(vault_name, target_path)
  when "help"
    help_message
  else
    help_message
  end
rescue => e
  STDERR.puts e.message

  if ENV["DEBUG"]
    STDERR.puts
    STDERR.puts e.backtrace
  end

  exit 1
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
2pass-1.1.0 bin/2pass