Class: MotherBrain::CliGateway::SubCommand::Plugin

Inherits:
MotherBrain::Cli::Base show all
Defined in:
lib/mb/cli_gateway/sub_commands/plugin.rb

Instance Method Summary collapse

Methods inherited from MotherBrain::Cli::Base

register_subcommand, ui

Instance Method Details

#init(path = Dir.pwd) ⇒ Object



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
36
37
# File 'lib/mb/cli_gateway/sub_commands/plugin.rb', line 10

def init(path = Dir.pwd)
   = File.join(path, 'metadata.rb')

  unless File.exist?()
    ui.say "#{path} is not a cookbook"
    exit(1)
  end

  cookbook = CookbookMetadata.from_file()
  config = { name: cookbook.name, groups: %w[default] }
  template 'bootstrap.json', File.join(path, 'bootstrap.json'), config
  template 'motherbrain.rb', File.join(path, 'motherbrain.rb'), config

  ui.say [
    "",
    "motherbrain plugin created.",
    "",
    "Take a look at motherbrain.rb and bootstrap.json,",
    "and then bootstrap with:",
    "",
    "  mb #{cookbook.name} bootstrap bootstrap.json",
    "",
    "To see all available commands, run:",
    "",
    "  mb #{cookbook.name} help",
    "\n"
  ].join("\n")
end

#install(name) ⇒ Object



43
44
45
46
# File 'lib/mb/cli_gateway/sub_commands/plugin.rb', line 43

def install(name)
  plugin = plugin_manager.install(name, options[:version])
  ui.say "Successfully installed #{plugin}"
end

#listObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mb/cli_gateway/sub_commands/plugin.rb', line 53

def list
  if options[:remote]
    ui.say "\n"
    ui.say "** listing installed and remote plugins..."
    ui.say "\n"
  else
    ui.say "\n"
    ui.say "** listing installed plugins...\n"
    ui.say "\n"
  end

  plugins = plugin_manager.list(remote: options[:remote])

  if plugins.empty?
    errmsg = "No plugins found in your Berkshelf: '#{Application.plugin_manager.berkshelf_path}'"

    if options[:remote]
      errmsg << " or on remote: '#{Application.config.chef.api_url}'"
    end

    ui.say errmsg
    exit(0)
  end

  plugins.group_by(&:name).each do |name, plugins|
    versions = plugins.collect(&:version).reverse!
    ui.say "#{name}: #{versions.join(', ')}"
  end
end

#show(name) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mb/cli_gateway/sub_commands/plugin.rb', line 91

def show(name)
  unless plugin = plugin_manager.find(name, options[:version], remote: options[:remote])
    if options[:version]
      errmsg = "#{name} (#{options[:version]}) not"
    else
      errmsg = "No versions of #{name}"
    end
    errmsg << " found in your Berkshelf"
    errmsg << " or on the remote Chef server" if options[:remote]
    ui.say errmsg
    ui.say "You can search the Chef server with '--remote'" unless options[:remote]
    exit(1)
  end

  pp_plugin(plugin)
end

#uninstall(name) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/mb/cli_gateway/sub_commands/plugin.rb', line 113

def uninstall(name)
  if plugin = plugin_manager.uninstall(name, options[:version])
    ui.say "Successfully uninstalled #{plugin}"
  else
    ui.say "#{name} (#{options[:version]}) was not installed"
  end
end