Class: OnePass::CLI
- Inherits:
-
Thor
- Object
- Thor
- OnePass::CLI
- 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
- #__version ⇒ Object
- #list(folder) ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #search(query) ⇒ Object
- #show(name) ⇒ Object
Instance Method Details
#__version ⇒ Object
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 |
#login ⇒ Object
20 21 22 |
# File 'lib/OnePass/cli.rb', line 20 def login OnePass::Application.save .vault end |
#logout ⇒ Object
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] = [k] if .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 .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 |