Class: MediaWikiVagrant::Config

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

Overview

Provides a command-line interface for configuration of MediaWiki-Vagrant settings.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PluginEnvironment

#initialize, #interactive_out?

Class Method Details

.synopsisObject



14
15
16
# File 'lib/mediawiki-vagrant/config.rb', line 14

def self.synopsis
  'configures mediawiki-vagrant settings'
end

Instance Method Details

#executeObject



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
72
73
# File 'lib/mediawiki-vagrant/config.rb', line 18

def execute
  options = {
    interactive: false,
    list: false,
    required: false,
    get: [],
    unset: [],
  }

  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant config [options] [name] [value]'
    o.separator ''
    o.separator 'Options:'
    o.separator ''

    o.on('--all', 'Configure all settings') do
      options[:interactive] = true
    end

    o.on('--required', 'Configure only required settings') do
      options[:interactive] = true
      options[:required] = true
    end

    o.on('--list', 'List all settings') do
      options[:list] = true
    end

    o.on('--get NAME', 'Get a configured setting') do |name|
      options[:get] << name
    end

    o.on('--unset NAME', 'Remove a configured setting') do |name|
      options[:unset] << name
    end
  end

  argv = parse_options(opts)
  return unless argv

  if options[:list]
    list_settings
  elsif options[:interactive]
    interactively_configure(options)
  elsif argv.length == 2
    configure_setting(*argv)
  elsif options[:get].any? || options[:unset].any?
    get_settings(options[:get])
    unset_settings(options[:unset])
  else
    @env.ui.error opts
    return 1
  end

  0
end