Class: Passdb::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/passdb/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



11
12
13
14
# File 'lib/passdb/cli.rb', line 11

def initialize(*)
  super
  Thor::Shell::Basic.new
end

Instance Method Details

#searchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/passdb/cli.rb', line 21

def search
  opts = options.dup
  if opts["vendor"] && opts["criteria"]
    puts "You can't specify both a vendor and a free-form criteria"
    exit 1
  end

  if !(opts["vendor"] || opts["criteria"])
    puts "You need to specify either --vendor or --criteria"
    exit 1
  end
  
  results = nil
  if opts["vendor"]
    results = Passdb.search(:vendor => opts["vendor"])
  else
    results = Passdb.search(:criteria => opts["criteria"])
  end

  puts "#{results.size} entries were found:"
  results.each do |entry|
    puts "  #{entry.name}"
    entry.attributes.each do |name, value|
      puts "    #{name} => #{value}"
    end
  end
end

#versionObject



50
51
52
# File 'lib/passdb/cli.rb', line 50

def version
  say "Passdb #{Passdb::VERSION::STRING}"
end