Class: Berkshelf::Shelf

Inherits:
Thor
  • Object
show all
Defined in:
lib/berkshelf/commands/shelf.rb

Overview

All tasks that operate on the Berkshelf shelf.

Instance Method Summary collapse

Instance Method Details

#listObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/berkshelf/commands/shelf.rb', line 5

def list
  cookbooks = store.cookbooks.inject({}) do |hash, cookbook|
    (hash[cookbook.cookbook_name] ||= []).push(cookbook.version)
    hash
  end

  if cookbooks.empty?
    Berkshelf.formatter.msg "There are no cookbooks in the Berkshelf shelf"
  else
    Berkshelf.formatter.msg "Cookbooks in the Berkshelf shelf:"
    cookbooks.sort.each do |cookbook, versions|
      Berkshelf.formatter.msg("  * #{cookbook} (#{versions.sort.join(", ")})")
    end
  end
end

#show(name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/berkshelf/commands/shelf.rb', line 23

def show(name)
  cookbooks = find(name, options[:version])

  if options[:version]
    Berkshelf.formatter.msg "Displaying '#{name}' (#{options[:version]}) in the Berkshelf shelf:"
  else
    Berkshelf.formatter.msg "Displaying all versions of '#{name}' in the Berkshelf shelf:"
  end

  cookbooks.each do |cookbook|
    Berkshelf.formatter.info(cookbook)
    Berkshelf.formatter.msg("\n")
  end
end

#uninstall(name) ⇒ Object



41
42
43
44
# File 'lib/berkshelf/commands/shelf.rb', line 41

def uninstall(name)
  cookbooks = find(name, options[:version])
  cookbooks.each { |c| uninstall_cookbook(c, options[:force]) }
end