Class: ListTool::App::ShowItemsCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/list_tool/app/commands/show_items_command.rb

Class Method Summary collapse

Class Method Details

.execute(options, lister) ⇒ Object

Raises:



22
23
24
25
26
# File 'lib/list_tool/app/commands/show_items_command.rb', line 22

def self.execute options, lister
  items = options[:list].nil? ? lister.list() : lister.list(options[:list])
  raise ListNotFoundError if items.nil?
  Printer.print_items( items )
end

.helpObject



28
29
30
# File 'lib/list_tool/app/commands/show_items_command.rb', line 28

def self.help
  "  s,  show-items [LIST]\t\tPrint contents of default or given list"
end

.match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/list_tool/app/commands/show_items_command.rb', line 6

def self.match? arg
  ['s', 'show-items'].include? arg
end

.parse(argv) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/list_tool/app/commands/show_items_command.rb', line 10

def self.parse argv
  raise ArgumentError, "expected argument to be an array, #{argv.class} given" unless argv.is_a? Array
  list = argv.shift

  if list
    list = Integer( list ) - 1 rescue raise(ArgumentError, 'list number must be an integer')
    raise ArgumentError, "list number can't be less than 1" if list < 0
  end

  list ? {list: list} : {}
end