#!/usr/bin/env ruby require_relative "../lib/2pass" def help_message puts <<~HELP Usage: 2pass add - Add new secret 2pass get - Get content by ID from the specified vault 2pass list - List the content of the specified vault 2pass link - 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