Class: MediaWikiVagrant::Roles::Root

Inherits:
Object
  • Object
show all
Defined in:
lib/mediawiki-vagrant/roles/root.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ Root

Returns a new instance of Root



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/mediawiki-vagrant/roles/root.rb', line 11

def initialize(argv, env)
  super

  @args, @command, @sub_args = split_main_and_subcommand(argv)

  @subcommands = Vagrant::Registry.new
  @subcommands.register(:list) do
    require_relative 'list'
    List
  end
  @subcommands.register(:reset) do
    require_relative 'reset'
    Reset
  end
  @subcommands.register(:enable) do
    require_relative 'enable'
    Enable
  end
  @subcommands.register(:disable) do
    require_relative 'disable'
    Disable
  end
  @subcommands.register(:info) do
    require_relative 'info'
    Info
  end
end

Class Method Details

.synopsisObject



7
8
9
# File 'lib/mediawiki-vagrant/roles/root.rb', line 7

def self.synopsis
  'manage mediawiki-vagrant roles: list, enable, disable, etc.'
end

Instance Method Details

#executeObject



39
40
41
42
43
44
45
46
# File 'lib/mediawiki-vagrant/roles/root.rb', line 39

def execute
  return help if @args.include?('-h') || @args.include?('--help')

  command_class = @subcommands.get(@command.to_sym) if @command
  return help if !command_class || !@command

  command_class.new(@sub_args, @env).execute
end

#helpObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/mediawiki-vagrant/roles/root.rb', line 48

def help
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant roles <command> [<args>]'
    o.separator ''
    o.separator 'Available subcommands:'

    commands = {}
    longest = 0
    @subcommands.each do |key, klass|
      key           = key.to_s
      commands[key] = klass.synopsis
      longest       = key.length if key.length > longest
    end

    commands.keys.sort.each do |key|
      o.separator "    #{key.ljust(longest + 1)} #{commands[key]}"
    end

    o.separator ''
    o.separator 'For help on any individual command run `vagrant roles COMMAND -h`'
  end
  @env.ui.info(opts.help, prefix: false)
end