nugrant 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -0
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/nugrant.rb +5 -0
- data/lib/nugrant/helper/yaml.rb +19 -0
- data/lib/nugrant/parameters.rb +16 -11
- data/lib/nugrant/vagrant/command/parameters.rb +125 -0
- data/lib/nugrant/vagrant/command/root.rb +78 -0
- data/lib/nugrant/vagrant/config/user.rb +29 -0
- data/lib/nugrant/version.rb +1 -1
- data/lib/vagrant_init.rb +4 -4
- data/test/lib/nugrant/test_parameters.rb +22 -2
- data/test/resources/Vagrantfile +3 -0
- data/test/resources/json/params_boolean.json +1 -0
- data/test/resources/json/params_empty.json +0 -0
- data/test/resources/json/params_list.json +1 -0
- data/test/resources/yml/params_boolean.yml +1 -0
- data/test/resources/yml/params_empty.yml +0 -0
- data/test/resources/yml/params_list.yml +2 -0
- metadata +25 -4
- data/lib/nugrant/vagrant/user_command.rb +0 -86
- data/lib/nugrant/vagrant/user_parameters.rb +0 -27
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 0.0.12
|
2
|
+
|
3
|
+
* Added travis configuration file
|
4
|
+
* Added travis build status icon to readme
|
5
|
+
* Fixed a bug when `.vagrantuser` file is empty or not a hash type
|
6
|
+
* Improved parameters command
|
7
|
+
* The parameters command is now a proper subcommand
|
8
|
+
* An option has been added to see system parameters
|
9
|
+
* An option has been added to see user parameters
|
10
|
+
* An option has been added to see project parameters
|
11
|
+
|
1
12
|
# 0.0.11
|
2
13
|
|
3
14
|
* Updated README file for installation via rubygems.org
|
data/README.md
CHANGED
data/lib/nugrant.rb
CHANGED
@@ -3,6 +3,11 @@ require 'nugrant/config'
|
|
3
3
|
require 'nugrant/parameter_bag'
|
4
4
|
require 'nugrant/parameters'
|
5
5
|
|
6
|
+
unless defined?(KeyError)
|
7
|
+
class KeyError < IndexError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
6
11
|
module Nugrant
|
7
12
|
def self.create_parameters(options)
|
8
13
|
config = Nugrant::Config.new(options)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nugrant
|
2
|
+
module Helper
|
3
|
+
class Yaml
|
4
|
+
def self.format(string, options = {})
|
5
|
+
lines = string.send(string.respond_to?(:lines) ? :lines : :to_s).to_a
|
6
|
+
lines = lines.drop(1)
|
7
|
+
|
8
|
+
if options[:indent]
|
9
|
+
indent_text = " " * options[:indent]
|
10
|
+
lines = lines.map do |line|
|
11
|
+
indent_text + line
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
return lines.join("")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/nugrant/parameters.rb
CHANGED
@@ -55,24 +55,29 @@ module Nugrant
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def load_parameters_file(file_path)
|
58
|
-
|
59
|
-
|
58
|
+
data = parse(file_path)
|
59
|
+
if data == nil || !data.kind_of?(Hash)
|
60
|
+
return
|
60
61
|
end
|
61
62
|
|
63
|
+
restricted_key = has_restricted_keys?(data)
|
64
|
+
if restricted_key
|
65
|
+
raise ArgumentError, "The key '#{restricted_key}' has restricted usage and cannot be defined"
|
66
|
+
end
|
67
|
+
|
68
|
+
return data
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse(file_path)
|
72
|
+
return if not File.exists?(file_path)
|
73
|
+
|
62
74
|
begin
|
63
75
|
File.open(file_path, "rb") do |file|
|
64
76
|
parsing_method = "parse_#{@config.params_filetype}"
|
65
|
-
|
66
|
-
|
67
|
-
restricted_key = has_restricted_keys?(result)
|
68
|
-
if restricted_key
|
69
|
-
raise ArgumentError, "The key '#{restricted_key}' has restricted usage and cannot be defined"
|
70
|
-
end
|
71
|
-
|
72
|
-
return result
|
77
|
+
return send(parsing_method, file.read)
|
73
78
|
end
|
74
79
|
rescue => error
|
75
|
-
|
80
|
+
# TODO: log this message "Could not parse the user #{@config.params_filetype} parameters file '#{file_path}': #{error}"
|
76
81
|
end
|
77
82
|
end
|
78
83
|
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
require 'nugrant/helper/yaml'
|
3
|
+
|
4
|
+
module Nugrant
|
5
|
+
module Vagrant
|
6
|
+
module Command
|
7
|
+
class Parameters < ::Vagrant::Command::Base
|
8
|
+
def initialize(arguments, environment)
|
9
|
+
super(arguments, environment)
|
10
|
+
|
11
|
+
@show_help = false
|
12
|
+
@show_system = false
|
13
|
+
@show_user = false
|
14
|
+
@show_project = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_parser()
|
18
|
+
return OptionParser.new do |parser|
|
19
|
+
parser.banner = "Usage: vagrant user parameters [<options>]"
|
20
|
+
parser.separator ""
|
21
|
+
|
22
|
+
parser.separator "Available options:"
|
23
|
+
parser.separator ""
|
24
|
+
|
25
|
+
parser.on("-h", "--help", "Print this help") do
|
26
|
+
@show_help = true
|
27
|
+
end
|
28
|
+
|
29
|
+
parser.on("-s", "--system", "Show only system parameters") do
|
30
|
+
@show_system = true
|
31
|
+
end
|
32
|
+
|
33
|
+
parser.on("-u", "--user", "Show only user parameters") do
|
34
|
+
@show_user = true
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.on("-p", "--project", "Show only project parameters") do
|
38
|
+
@show_project = true
|
39
|
+
end
|
40
|
+
|
41
|
+
parser.separator ""
|
42
|
+
parser.separator "When no options is provided, the command prints the names and values \n" +
|
43
|
+
"of all parameters that would be available for usage in the Vagrantfile.\n" +
|
44
|
+
"The hierarchy of the parameters is respected, so the final values are\n" +
|
45
|
+
"displayed."
|
46
|
+
|
47
|
+
parser.separator ""
|
48
|
+
parser.separator "Notice: For now, defaults directly defined in the Vagrantfile are not \n" +
|
49
|
+
"considered by this command. This is something we would like to fix in \n" +
|
50
|
+
"the near future."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def execute
|
55
|
+
parser = create_parser()
|
56
|
+
arguments = parse_options(parser)
|
57
|
+
|
58
|
+
return help(parser) if @show_help
|
59
|
+
|
60
|
+
system() if @show_system
|
61
|
+
user() if @show_user
|
62
|
+
project() if @show_project
|
63
|
+
|
64
|
+
all() if !@show_system && !@show_user && !@show_project
|
65
|
+
|
66
|
+
return 0
|
67
|
+
end
|
68
|
+
|
69
|
+
def help(parser)
|
70
|
+
@env.ui.info(parser.help, :prefix => false)
|
71
|
+
end
|
72
|
+
|
73
|
+
def system()
|
74
|
+
parameters = Nugrant::Parameters.new()
|
75
|
+
|
76
|
+
print_header("System")
|
77
|
+
print_parameters(parameters.get_system_params())
|
78
|
+
end
|
79
|
+
|
80
|
+
def user()
|
81
|
+
parameters = Nugrant::Parameters.new()
|
82
|
+
|
83
|
+
print_header("User")
|
84
|
+
print_parameters(parameters.get_user_params())
|
85
|
+
end
|
86
|
+
|
87
|
+
def project()
|
88
|
+
parameters = Nugrant::Parameters.new()
|
89
|
+
|
90
|
+
print_header("Project")
|
91
|
+
print_parameters(parameters.get_project_params())
|
92
|
+
end
|
93
|
+
|
94
|
+
def all()
|
95
|
+
parameters = Nugrant::Parameters.new()
|
96
|
+
|
97
|
+
print_parameters(parameters.get_params())
|
98
|
+
end
|
99
|
+
|
100
|
+
def print_header(kind)
|
101
|
+
@env.ui.info("#{kind.capitalize} parameters", :prefix => false)
|
102
|
+
@env.ui.info("-----------------------------------------------", :prefix => false)
|
103
|
+
end
|
104
|
+
|
105
|
+
def print_parameters(parameters)
|
106
|
+
if !parameters || parameters.empty?()
|
107
|
+
@env.ui.info(" Empty", :prefix => false)
|
108
|
+
@env.ui.info("", :prefix => false)
|
109
|
+
return
|
110
|
+
end
|
111
|
+
|
112
|
+
data = {
|
113
|
+
'config' => {
|
114
|
+
'user' => parameters
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
string = Nugrant::Helper::Yaml.format(data.to_yaml)
|
119
|
+
@env.ui.info(string, :prefix => false)
|
120
|
+
@env.ui.info("", :prefix => false)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
module Vagrant
|
5
|
+
module Command
|
6
|
+
class Root < ::Vagrant::Command::Base
|
7
|
+
def initialize(arguments, environment)
|
8
|
+
super(arguments, environment)
|
9
|
+
|
10
|
+
@arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments)
|
11
|
+
|
12
|
+
# Change super class available arguments to main ones only
|
13
|
+
@argv = @arguments
|
14
|
+
|
15
|
+
@subcommands = ::Vagrant::Registry.new()
|
16
|
+
@subcommands.register(:parameters) do
|
17
|
+
require File.expand_path("../parameters", __FILE__)
|
18
|
+
Parameters
|
19
|
+
end
|
20
|
+
|
21
|
+
@show_help = false
|
22
|
+
@show_version = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_parser()
|
26
|
+
return OptionParser.new do |parser|
|
27
|
+
parser.banner = "Usage: vagrant user [-h] [-v] <command> [<args>]"
|
28
|
+
|
29
|
+
parser.separator ""
|
30
|
+
parser.on("-h", "--help", "Print this help") do
|
31
|
+
@show_help = true
|
32
|
+
end
|
33
|
+
|
34
|
+
parser.on("-v", "--version", "Print plugin version and exit.") do
|
35
|
+
@show_version = true
|
36
|
+
end
|
37
|
+
|
38
|
+
parser.separator ""
|
39
|
+
parser.separator "Available subcommands:"
|
40
|
+
|
41
|
+
keys = []
|
42
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
43
|
+
|
44
|
+
keys.sort.each do |key|
|
45
|
+
parser.separator " #{key}"
|
46
|
+
end
|
47
|
+
|
48
|
+
parser.separator ""
|
49
|
+
parser.separator "For help on any individual command run `vagrant user COMMAND -h`"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute
|
54
|
+
parser = create_parser()
|
55
|
+
arguments = parse_options(parser)
|
56
|
+
|
57
|
+
return version() if @show_version
|
58
|
+
return help(parser) if @show_help
|
59
|
+
|
60
|
+
command_class = @subcommands.get(@subcommand.to_sym) if @subcommand
|
61
|
+
return help(parser) if !command_class || !@subcommand
|
62
|
+
|
63
|
+
@logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}")
|
64
|
+
|
65
|
+
command_class.new(@subarguments, @env).execute
|
66
|
+
end
|
67
|
+
|
68
|
+
def help(parser)
|
69
|
+
@env.ui.info(parser.help, :prefix => false)
|
70
|
+
end
|
71
|
+
|
72
|
+
def version()
|
73
|
+
@env.ui.info("Nugrant version #{Nugrant::VERSION}", :prefix => false)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
module Vagrant
|
5
|
+
module Config
|
6
|
+
class User < ::Vagrant::Config::Base
|
7
|
+
def initialize()
|
8
|
+
@parameters = Nugrant::Parameters.new()
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](param_name)
|
12
|
+
return @parameters[param_name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return @parameters.method_missing(method, *args, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def defaults(parameters)
|
20
|
+
@parameters.defaults(parameters)
|
21
|
+
end
|
22
|
+
|
23
|
+
def defaults=(parameters)
|
24
|
+
@parameters.defaults=(parameters)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/nugrant/version.rb
CHANGED
data/lib/vagrant_init.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# This module will initialize the vagrant plugin
|
2
|
-
require 'nugrant/vagrant/
|
3
|
-
require 'nugrant/vagrant/
|
2
|
+
require 'nugrant/vagrant/command/root'
|
3
|
+
require 'nugrant/vagrant/config/user'
|
4
4
|
|
5
5
|
# Plugin bootstrap
|
6
|
-
Vagrant.commands.register(:user) { Nugrant::Vagrant::
|
7
|
-
Vagrant.config_keys.register(:user) { Nugrant::Vagrant::
|
6
|
+
Vagrant.commands.register(:user) { Nugrant::Vagrant::Command::Root }
|
7
|
+
Vagrant.config_keys.register(:user) { Nugrant::Vagrant::Config::User }
|
@@ -166,14 +166,14 @@ class Nugrant::TestParameters < Test::Unit::TestCase
|
|
166
166
|
|
167
167
|
def test_restricted_defaults_usage()
|
168
168
|
filetypes.each do |params_filetype|
|
169
|
-
assert_raise(
|
169
|
+
assert_raise(ArgumentError) do
|
170
170
|
results = create_parameters(params_filetype, "params_defaults_at_root", invalid_path, invalid_path)
|
171
171
|
puts("Results: #{results.inspect} (Should have thrown!)")
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
175
|
filetypes.each do |params_filetype|
|
176
|
-
assert_raise(
|
176
|
+
assert_raise(ArgumentError) do
|
177
177
|
results = create_parameters(params_filetype, "params_defaults_not_at_root", invalid_path, invalid_path)
|
178
178
|
puts("Results: #{results.inspect} (Should have thrown!)")
|
179
179
|
end
|
@@ -195,6 +195,26 @@ class Nugrant::TestParameters < Test::Unit::TestCase
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
+
def test_empty_file()
|
199
|
+
filetypes.each do |params_filetype|
|
200
|
+
parameters = create_parameters(params_filetype, "params_empty", invalid_path, invalid_path)
|
201
|
+
parameters.defaults({"test" => "value"})
|
202
|
+
|
203
|
+
assert_equal("value", parameters.test)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_file_not_hash()
|
208
|
+
["boolean", "list"].each do |wrong_type|
|
209
|
+
filetypes.each do |params_filetype|
|
210
|
+
parameters = create_parameters(params_filetype, "params_#{wrong_type}", invalid_path, invalid_path)
|
211
|
+
parameters.defaults({"test" => "value"})
|
212
|
+
|
213
|
+
assert_equal("value", parameters.test)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
198
218
|
def filetypes()
|
199
219
|
@@PARAMS_FILETYPES
|
200
220
|
end
|
data/test/resources/Vagrantfile
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
false
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
["value", "second"]
|
@@ -0,0 +1 @@
|
|
1
|
+
true
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nugrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: deep_merge
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- .gitattributes
|
75
75
|
- .gitignore
|
76
76
|
- .project
|
77
|
+
- .travis.yml
|
77
78
|
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
@@ -81,10 +82,12 @@ files:
|
|
81
82
|
- Rakefile
|
82
83
|
- lib/nugrant.rb
|
83
84
|
- lib/nugrant/config.rb
|
85
|
+
- lib/nugrant/helper/yaml.rb
|
84
86
|
- lib/nugrant/parameter_bag.rb
|
85
87
|
- lib/nugrant/parameters.rb
|
86
|
-
- lib/nugrant/vagrant/
|
87
|
-
- lib/nugrant/vagrant/
|
88
|
+
- lib/nugrant/vagrant/command/parameters.rb
|
89
|
+
- lib/nugrant/vagrant/command/root.rb
|
90
|
+
- lib/nugrant/vagrant/config/user.rb
|
88
91
|
- lib/nugrant/version.rb
|
89
92
|
- lib/vagrant_init.rb
|
90
93
|
- nugrant.gemspec
|
@@ -94,9 +97,12 @@ files:
|
|
94
97
|
- test/resources/.vagrantuser
|
95
98
|
- test/resources/README.md
|
96
99
|
- test/resources/Vagrantfile
|
100
|
+
- test/resources/json/params_boolean.json
|
97
101
|
- test/resources/json/params_combinations.json
|
98
102
|
- test/resources/json/params_defaults_at_root.json
|
99
103
|
- test/resources/json/params_defaults_not_at_root.json
|
104
|
+
- test/resources/json/params_empty.json
|
105
|
+
- test/resources/json/params_list.json
|
100
106
|
- test/resources/json/params_project_1.json
|
101
107
|
- test/resources/json/params_project_2.json
|
102
108
|
- test/resources/json/params_simple.json
|
@@ -106,9 +112,12 @@ files:
|
|
106
112
|
- test/resources/json/params_user_1.json
|
107
113
|
- test/resources/json/params_user_2.json
|
108
114
|
- test/resources/json/params_windows_eol.json
|
115
|
+
- test/resources/yml/params_boolean.yml
|
109
116
|
- test/resources/yml/params_combinations.yml
|
110
117
|
- test/resources/yml/params_defaults_at_root.yml
|
111
118
|
- test/resources/yml/params_defaults_not_at_root.yml
|
119
|
+
- test/resources/yml/params_empty.yml
|
120
|
+
- test/resources/yml/params_list.yml
|
112
121
|
- test/resources/yml/params_project_1.yml
|
113
122
|
- test/resources/yml/params_project_2.yml
|
114
123
|
- test/resources/yml/params_simple.yml
|
@@ -130,12 +139,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
139
|
- - ! '>='
|
131
140
|
- !ruby/object:Gem::Version
|
132
141
|
version: '0'
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
hash: -519440520645182635
|
133
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
146
|
none: false
|
135
147
|
requirements:
|
136
148
|
- - ! '>='
|
137
149
|
- !ruby/object:Gem::Version
|
138
150
|
version: '0'
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
hash: -519440520645182635
|
139
154
|
requirements: []
|
140
155
|
rubyforge_project:
|
141
156
|
rubygems_version: 1.8.24
|
@@ -149,9 +164,12 @@ test_files:
|
|
149
164
|
- test/resources/.vagrantuser
|
150
165
|
- test/resources/README.md
|
151
166
|
- test/resources/Vagrantfile
|
167
|
+
- test/resources/json/params_boolean.json
|
152
168
|
- test/resources/json/params_combinations.json
|
153
169
|
- test/resources/json/params_defaults_at_root.json
|
154
170
|
- test/resources/json/params_defaults_not_at_root.json
|
171
|
+
- test/resources/json/params_empty.json
|
172
|
+
- test/resources/json/params_list.json
|
155
173
|
- test/resources/json/params_project_1.json
|
156
174
|
- test/resources/json/params_project_2.json
|
157
175
|
- test/resources/json/params_simple.json
|
@@ -161,9 +179,12 @@ test_files:
|
|
161
179
|
- test/resources/json/params_user_1.json
|
162
180
|
- test/resources/json/params_user_2.json
|
163
181
|
- test/resources/json/params_windows_eol.json
|
182
|
+
- test/resources/yml/params_boolean.yml
|
164
183
|
- test/resources/yml/params_combinations.yml
|
165
184
|
- test/resources/yml/params_defaults_at_root.yml
|
166
185
|
- test/resources/yml/params_defaults_not_at_root.yml
|
186
|
+
- test/resources/yml/params_empty.yml
|
187
|
+
- test/resources/yml/params_list.yml
|
167
188
|
- test/resources/yml/params_project_1.yml
|
168
189
|
- test/resources/yml/params_project_2.yml
|
169
190
|
- test/resources/yml/params_simple.yml
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'nugrant'
|
2
|
-
|
3
|
-
module Nugrant
|
4
|
-
module Vagrant
|
5
|
-
class UserCommand < ::Vagrant::Command::Base
|
6
|
-
HANDLED_SUBCOMMANDS = [
|
7
|
-
"parameters",
|
8
|
-
]
|
9
|
-
|
10
|
-
def initialize(arguments, environment)
|
11
|
-
super(arguments, environment)
|
12
|
-
|
13
|
-
@parameters = Nugrant::Parameters.new()
|
14
|
-
@options_parser = initialize_parsers()
|
15
|
-
|
16
|
-
@print_help = false
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize_parsers()
|
20
|
-
parser = OptionParser.new
|
21
|
-
|
22
|
-
parser.banner = "Usage: vagrant user subcommand [options]"
|
23
|
-
|
24
|
-
parser.on("-h", "--help", "Print this help") do
|
25
|
-
@print_help
|
26
|
-
end
|
27
|
-
|
28
|
-
parser.separator ""
|
29
|
-
parser.separator "Available subcommands:"
|
30
|
-
|
31
|
-
HANDLED_SUBCOMMANDS.each do |subcommand|
|
32
|
-
parser.separator " #{subcommand}"
|
33
|
-
end
|
34
|
-
|
35
|
-
return parser
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute()
|
39
|
-
subcommands = parse_options(@options_parser)
|
40
|
-
if not subcommands
|
41
|
-
subcommands = ["parameters"]
|
42
|
-
end
|
43
|
-
|
44
|
-
subcommands = validate_subcommands(subcommands)
|
45
|
-
if not subcommands
|
46
|
-
safe_puts(@options_parser.help())
|
47
|
-
return
|
48
|
-
end
|
49
|
-
|
50
|
-
# At this point, subcommands are valid
|
51
|
-
subcommands.each do |subcommand|
|
52
|
-
execute_subcommand(subcommand)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def execute_subcommand(subcommand)
|
57
|
-
send(:parameters)
|
58
|
-
end
|
59
|
-
|
60
|
-
def parameters()
|
61
|
-
parameters = {
|
62
|
-
'config' => {
|
63
|
-
'user' => @parameters.get_params()
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
safe_puts(parameters.to_yaml(:Separator => ""))
|
68
|
-
end
|
69
|
-
|
70
|
-
def handled_subcommand?(subcommand)
|
71
|
-
return HANDLED_SUBCOMMANDS.find_index(subcommand)
|
72
|
-
end
|
73
|
-
|
74
|
-
def validate_subcommands(subcommands)
|
75
|
-
subcommands.each do |subcommand|
|
76
|
-
if not handled_subcommand?(subcommand)
|
77
|
-
puts "Unknown subcommand [#{subcommand}]."
|
78
|
-
return nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
return subcommands
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'nugrant'
|
2
|
-
|
3
|
-
module Nugrant
|
4
|
-
module Vagrant
|
5
|
-
class UserParameters < ::Vagrant::Config::Base
|
6
|
-
def initialize()
|
7
|
-
@parameters = Nugrant::Parameters.new()
|
8
|
-
end
|
9
|
-
|
10
|
-
def [](param_name)
|
11
|
-
return @parameters[param_name]
|
12
|
-
end
|
13
|
-
|
14
|
-
def method_missing(method, *args, &block)
|
15
|
-
return @parameters.method_missing(method, *args, &block)
|
16
|
-
end
|
17
|
-
|
18
|
-
def defaults(parameters)
|
19
|
-
@parameters.defaults(parameters)
|
20
|
-
end
|
21
|
-
|
22
|
-
def defaults=(parameters)
|
23
|
-
@parameters.defaults=(parameters)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|