Class: MediaWikiVagrant::Roles::Change

Inherits:
Object
  • Object
show all
Includes:
PluginEnvironment, SettingsPlugin
Defined in:
lib/mediawiki-vagrant/roles/change.rb

Overview

Abstract command for making changes to currently enabled roles.

Direct Known Subclasses

Disable, Enable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PluginEnvironment

#initialize, #interactive_out?

Class Method Details

.synopsisObject



12
13
14
# File 'lib/mediawiki-vagrant/roles/change.rb', line 12

def self.synopsis
  "#{mode} a mediawiki-vagrant role"
end

Instance Method Details

#executeObject

Raises:

  • (Vagrant::Errors::CLIInvalidUsage)


16
17
18
19
20
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mediawiki-vagrant/roles/change.rb', line 16

def execute
  options = {
    provision: false,
  }

  opts = OptionParser.new do |o|
    subcommands = o.default_argv.first(2).join(' ')

    o.banner = "Usage: vagrant #{subcommands} <name> [<name2> <name3> ...] [-h | -p]"
    o.separator ''
    o.separator "  #{banner}"
    o.separator ''
    o.separator 'Options:'
    o.separator ''


    o.on('-p', '--provision', "Run 'vagrant provision' afterwards") do
      options[:provision] = true
    end
  end

  argv = parse_options(opts)
  return unless argv
  raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length < 1

  possible = possible_roles
  roles = argv.map(&:downcase)

  roles.each do |r|
    unless possible.include? r
      @env.ui.error role_error(r)
      return 1
    end
  end

  roles = new_roles(roles)
  changes = @mwv.load_settings(roles) - @mwv.load_settings

  @mwv.update_roles(roles)

  if options[:provision]
    with_target_vms(nil, single_target: true) do |vm|
      if vm.state.id == :running
        @mwv.trigger_reload if changes.any?
        vm.action :provision
      else
        vm.action :up, provision_enabled: true
      end
    end
  else
    @env.ui.info 'Ok. Run `vagrant provision` to apply your changes.'
    describe_settings_changes(changes)
  end

  0
end