class OnePass::CLI

OnePass CLI

Constants

SHOW_OPTIONS

Public Instance Methods

__version() click to toggle source
# File lib/OnePass/cli.rb, line 14
def __version
  puts "#{File.basename $PROGRAM_NAME} version #{OnePass::VERSION}"
end
list(folder) click to toggle source
# File lib/OnePass/cli.rb, line 66
def list(folder)
end
login() click to toggle source
# File lib/OnePass/cli.rb, line 20
def login
  OnePass::Application.save options.vault
end
logout() click to toggle source
# File lib/OnePass/cli.rb, line 25
def logout
  OnePass::Application.forget
end
show(name) click to toggle source
# File lib/OnePass/cli.rb, line 35
def show(name)
  # Check for multiple mutex args
  type = SHOW_OPTIONS.each_with_object(Hash.new) do |k, hash|
    hash[k] = options[k] if options.has_key?(k)
  end
  if type.length > 1
    puts "Use only one of #{SHOW_OPTIONS.collect { |switch| '--' + switch }.join ', '}"
    exit 1
  end

  # TODO: Check if name looks like a UUID
  # otherwise, search for title by substring, return first
  app = OnePass::Application.new
  reply_type = type.keys.first.to_sym
  reply = app.show name, reply_type
  if options.clip
    IO.popen('pbcopy', 'w') { |f| f << (reply_type == :all ? JSON.generate(reply) : reply) }
  else
    print reply_type == :all ? JSON.pretty_generate(reply) : reply
    puts if $stdout.isatty
  end
end