Class: Pwl::Commands::List

Inherits:
Base
  • Object
show all
Defined in:
lib/pwl/commands/list.rb

Instance Method Summary collapse

Methods inherited from Base

default_locker_file, exit_codes_help

Instance Method Details

#call(args, options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pwl/commands/list.rb', line 4

def call(args, options)
  options.default :separator => ' '

  begin
    locker = open_locker(options)

    if !options.long
      result = locker.list(args[0]).join(options.separator)
    else
      matching_names = locker.list(args[0])

      result = "total #{matching_names.size}#{$/}"

      matching_names.each do |name|
        e = locker.get(name)
        result << "#{e.uuid}\t#{e.name}#{$/}"
      end
    end

    if !result.blank?
      puts result
    else
      if args[0] # filter given
        exit_with(:list_empty_filter, options.verbose, args[0])
      else
        exit_with(:list_empty, options.verbose)
      end
    end
  rescue Dialog::Cancelled
    exit_with(:aborted, options.verbose)
  end
end