Class: OnePass::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/OnePass/cli.rb

Overview

OnePass CLI

Constant Summary collapse

SHOW_OPTIONS =
%w( all username password url uuid title ).freeze

Instance Method Summary collapse

Instance Method Details

#__versionObject



14
15
16
# File 'lib/OnePass/cli.rb', line 14

def __version
  puts "#{File.basename $PROGRAM_NAME} version #{OnePass::VERSION}"
end

#list(folder) ⇒ Object



66
67
# File 'lib/OnePass/cli.rb', line 66

def list(folder)
end

#loginObject



20
21
22
# File 'lib/OnePass/cli.rb', line 20

def 
  OnePass::Application.save options.vault
end

#logoutObject



25
26
27
# File 'lib/OnePass/cli.rb', line 25

def logout
  OnePass::Application.forget
end

#search(query) ⇒ Object



59
60
61
62
# File 'lib/OnePass/cli.rb', line 59

def search(query)
  app = OnePass::Application.new
  puts JSON.pretty_generate(app.search(query))
end

#show(name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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