Class: MediaWikiVagrant::Roles::List

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PluginEnvironment

#initialize, #interactive_out?

Class Method Details

.synopsisObject



8
9
10
# File 'lib/mediawiki-vagrant/roles/list.rb', line 8

def self.synopsis
  'lists available mediawiki-vagrant roles'
end

Instance Method Details

#executeObject



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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mediawiki-vagrant/roles/list.rb', line 12

def execute
  opts = {}
  optparse = OptionParser.new do |o|
    o.banner = 'Usage: vagrant roles list [options]'
    o.separator ''
    o.separator '  List available roles.'
    o.separator ''
    o.separator 'Options:'

    opts[:enabled] = false
    o.on('-e', '--enabled', 'Only show enabled roles') do
      opts[:enabled] = true
    end

    opts[:single_col] = !interactive_out?
    o.on('-1', '--onecol', 'Single column output without header/footer') do
      opts[:single_col] = true
      opts[:verbose] = false
    end

    opts[:verbose] = interactive_out?
    o.on('-q', '--quiet', 'Suppress output of headers and footers') do
      opts[:verbose] = false
    end

    o.on_tail('-h', '--help', 'Display this help screen') do
      @env.ui.info o
      exit
    end
  end

  return unless parse_options(optparse)

  if opts[:enabled]
    show_enabled(opts)
  else
    show_all(opts)
  end

  0
end


89
90
91
92
93
94
95
96
# File 'lib/mediawiki-vagrant/roles/list.rb', line 89

def print_cols(roles)
  if roles.any?
    col, *cols = roles.each_slice((roles.size / 3.0).ceil).to_a
    col.zip(*cols) do |a, b, c|
      @env.ui.info sprintf('%-26s %-26s %-26s', a, b, c)
    end
  end
end

#show_all(opts) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/mediawiki-vagrant/roles/list.rb', line 65

def show_all(opts)
  @env.ui.info "Available roles:\n" if opts[:verbose]
  enabled = @mwv.roles_enabled

  roles = @mwv.roles_available.sort.map do |role|
    prefix = enabled.include?(role) ? '*' : ' '
    "#{prefix} #{role}"
  end

  if opts[:single_col]
    roles.each { |x| @env.ui.info x }
  else
    print_cols(roles)
  end

  if opts[:verbose]
    @env.ui.info "\nRoles marked with '*' are enabled."
    @env.ui.info 'Note that roles enabled by dependency are not marked.'
    @env.ui.info 'Use `vagrant roles enable` & `vagrant roles disable` to customize.'
  end

  0
end

#show_enabled(opts) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/mediawiki-vagrant/roles/list.rb', line 54

def show_enabled(opts)
  @env.ui.info "Enabled roles:\n" if opts[:verbose]
  roles = @mwv.roles_enabled

  if opts[:single_col]
    roles.each { |x| @env.ui.info x }
  else
    print_cols(roles)
  end
end