nugrant 0.0.14 → 1.0.0.pre1
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/.buildpath +0 -0
- data/.gitignore +2 -0
- data/.project +0 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +24 -1
- data/LICENSE.txt +2 -2
- data/README.md +70 -23
- data/Rakefile +11 -1
- data/lib/nugrant.rb +12 -1
- data/lib/nugrant/config.rb +4 -5
- data/lib/nugrant/parameters.rb +0 -0
- data/lib/nugrant/vagrant/v1/command/parameters.rb +137 -0
- data/lib/nugrant/vagrant/v1/command/root.rb +80 -0
- data/lib/nugrant/vagrant/v1/config/user.rb +33 -0
- data/lib/nugrant/vagrant/v1/plugin.rb +6 -0
- data/lib/nugrant/vagrant/v2/command/parameters.rb +137 -0
- data/lib/nugrant/vagrant/v2/command/root.rb +81 -0
- data/lib/nugrant/vagrant/v2/config/user.rb +33 -0
- data/lib/nugrant/vagrant/v2/plugin.rb +22 -0
- data/lib/nugrant/version.rb +1 -1
- data/lib/vagrant_init.rb +1 -6
- data/nugrant.gemspec +11 -8
- data/test/resources/Vagrantfile.v1.fake +9 -0
- data/test/resources/Vagrantfile.v1.real +19 -0
- data/test/resources/Vagrantfile.v2.fake +9 -0
- data/test/resources/Vagrantfile.v2.real +22 -0
- metadata +34 -40
- data/lib/nugrant/vagrant/command/parameters.rb +0 -135
- data/lib/nugrant/vagrant/command/root.rb +0 -78
- data/lib/nugrant/vagrant/config/user.rb +0 -31
- data/test/resources/Vagrantfile +0 -8
data/.buildpath
CHANGED
File without changes
|
data/.gitignore
CHANGED
data/.project
CHANGED
File without changes
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,27 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in nugrant.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
vagrant_dependencies = {
|
7
|
+
'v1' => {
|
8
|
+
'home' => "C:/Users/Matt/.vagrant.d.v1",
|
9
|
+
'gem' => Proc.new do
|
10
|
+
gem "vagrant", "~> 1.0.5"
|
11
|
+
end,
|
12
|
+
},
|
13
|
+
'v2' => {
|
14
|
+
'home' => "C:/Users/Matt/.vagrant.d",
|
15
|
+
'gem' => Proc.new do
|
16
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
17
|
+
end,
|
18
|
+
},
|
19
|
+
}
|
20
|
+
|
21
|
+
vagrant_plugin_version = ENV['VAGRANT_PLUGIN_VERSION'] || "v2"
|
22
|
+
vagrant_dependency = vagrant_dependencies[vagrant_plugin_version]
|
23
|
+
|
24
|
+
ENV['VAGRANT_HOME'] = vagrant_dependency['home']
|
25
|
+
|
26
|
+
vagrant_dependency['gem'].call()
|
27
|
+
end
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Matthieu Vachon
|
1
|
+
Copyright (c) 2012-2013 Matthieu Vachon
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,48 +1,95 @@
|
|
1
1
|
# Nugrant [](https://travis-ci.org/maoueh/nugrant)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
config.
|
3
|
+
Nugrant is a library to easily handle parameters that need to be
|
4
|
+
injected into an application via different sources (system, user,
|
5
|
+
project, defaults).
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
But Nugrant is foremost a Vagrant plugin that will enhance
|
8
|
+
Vagrantfile to allow user specific configuration values. The plugin
|
9
|
+
will let users define a `.vagrantuser` file at different locations. This
|
10
|
+
file will contain parameters that will be injected into the Vagrantfile.
|
12
11
|
|
13
|
-
|
12
|
+
## Installation
|
14
13
|
|
15
|
-
|
16
|
-
config.vm.share_folder "git", "/git", "/home/user/work/git"
|
17
|
-
end
|
14
|
+
### Library
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
If you would like to use Nugrant as a library, simply reference
|
17
|
+
it as a dependency of your application. Probably by adding it to
|
18
|
+
your `Gemfile` or your `.gemspec` file.
|
22
19
|
|
23
|
-
|
20
|
+
nugrant ~> 0.0.15
|
24
21
|
|
25
|
-
|
26
|
-
to work correctly.
|
22
|
+
### Vagrant
|
27
23
|
|
28
|
-
|
29
|
-
|
24
|
+
If you would like to use Nugrant as a Vagrant plugin, the
|
25
|
+
detailed installation steps are provided below. Without a
|
26
|
+
doubt, you need Vagrant installed for those steps to work ;)
|
30
27
|
|
31
|
-
|
32
|
-
it
|
28
|
+
There are two different ways to install the gem. You can
|
29
|
+
install it via Vagrant or via the system gem container.
|
30
|
+
|
31
|
+
When you install via Vagrant, the main benefit is that
|
32
|
+
it's decoupled from other system gems. There is less
|
33
33
|
chance for this gem's dependencies, even if they are minimal,
|
34
34
|
to clash with gems already installed on your system. This is the
|
35
35
|
recommended installation method. To install, simply run:
|
36
36
|
|
37
37
|
> vagrant gem install nugrant
|
38
38
|
|
39
|
-
If you prefer to install the gem in a system wide
|
39
|
+
If you prefer to install the gem in a system wide manner,
|
40
40
|
please use this command instead:
|
41
41
|
|
42
42
|
> gem install nugrant
|
43
43
|
|
44
44
|
## Usage
|
45
45
|
|
46
|
+
Whether used as a library or a Vagrant plugin, Nugrant has some
|
47
|
+
common concepts that apply to both usages. The most important
|
48
|
+
one is the parameters hierarchy.
|
49
|
+
|
50
|
+
Nugrant can read parameters from various locations and will merge
|
51
|
+
them all together in a single set. Merging is done in a fairly
|
52
|
+
standard fashion.
|
53
|
+
|
54
|
+
Here the precedence rules that apply when merging parameters
|
55
|
+
from various location:
|
56
|
+
|
57
|
+
- Defaults
|
58
|
+
- System
|
59
|
+
- User
|
60
|
+
- Project
|
61
|
+
|
62
|
+
In text, this means that project parameters overrides user
|
63
|
+
parameters, user parameters overrides system parameters and
|
64
|
+
finally system parameters overrides defaults parameters.
|
65
|
+
|
66
|
+
### Library
|
67
|
+
|
68
|
+
Using Nugrant as a library to handle parameters from various
|
69
|
+
location is really easy. Two main classes need to be handled.
|
70
|
+
|
71
|
+
First, you need to create a `Nugrant::Config` object. This
|
72
|
+
configuration holds the values that needs to be customized
|
73
|
+
by your own application. This includes the different parameters paths
|
74
|
+
and the format of the parameters file.
|
75
|
+
|
76
|
+
### Vagrant
|
77
|
+
|
78
|
+
For example, let say the git repository you want to
|
79
|
+
expose is not located under the root folder of
|
80
|
+
your `Vagrantfile`. That means you will need to specify
|
81
|
+
an absolute host path to share the folder on the guest vm.
|
82
|
+
|
83
|
+
Your `Vagrantfile` would look like this:
|
84
|
+
|
85
|
+
Vagrant::Config.run do |config|
|
86
|
+
config.vm.share_folder "git", "/git", "/home/user/work/git"
|
87
|
+
end
|
88
|
+
|
89
|
+
However, what happens when multiple developers
|
90
|
+
need to share the same `Vagrantfile`? This is the main
|
91
|
+
use case this plugin address.
|
92
|
+
|
46
93
|
When Vagrant starts, via any of the `vagrant` commands,
|
47
94
|
it loads all vagrant plugins it founds under the `GEM_PATH`
|
48
95
|
variable. If you installed the plugin with one of the two
|
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
-
require "bundler/
|
1
|
+
require "bundler/setup"
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
|
+
# Immediately sync all stdout so that tools like buildbot can
|
5
|
+
# immediately load in the output.
|
6
|
+
$stdout.sync = true
|
7
|
+
$stderr.sync = true
|
8
|
+
|
9
|
+
# Change to the directory of this file.
|
10
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
11
|
+
|
12
|
+
Bundler::GemHelper.install_tasks
|
13
|
+
|
4
14
|
Rake::TestTask.new do |task|
|
5
15
|
task.test_files = FileList['test/**/test*.rb']
|
6
16
|
end
|
data/lib/nugrant.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'pathname'
|
2
2
|
require 'nugrant/config'
|
3
3
|
require 'nugrant/parameters'
|
4
4
|
|
@@ -7,6 +7,17 @@ unless defined?(KeyError)
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
if defined?(Vagrant)
|
11
|
+
case
|
12
|
+
when defined?(Vagrant::Plugin::V2)
|
13
|
+
require 'nugrant/vagrant/v2/plugin'
|
14
|
+
when Vagrant::VERSION =~ /1\.0\..*/
|
15
|
+
# Nothing to do, v1 plugins are picked by the vagrant_init.rb file
|
16
|
+
else
|
17
|
+
abort("You are trying to use Nugrant with an unsupported Vagrant version [#{Vagrant::VERSION}]")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
module Nugrant
|
11
22
|
def self.create_parameters(options)
|
12
23
|
config = Nugrant::Config.new(options)
|
data/lib/nugrant/config.rb
CHANGED
@@ -9,20 +9,19 @@ module Nugrant
|
|
9
9
|
attr :params_filetype, true
|
10
10
|
|
11
11
|
def self.user_base_path()
|
12
|
-
|
12
|
+
File.expand_path("~")
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.system_base_path()
|
16
|
-
# TODO: Fixme, find the right location to put system wide settings on windows...
|
17
16
|
if Config.on_windows?
|
18
|
-
return
|
17
|
+
return File.expand_path(ENV['PROGRAMDATA'] || ENV['ALLUSERSPROFILE'])
|
19
18
|
end
|
20
19
|
|
21
|
-
|
20
|
+
"/etc"
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.on_windows?()
|
25
|
-
|
24
|
+
(RbConfig::CONFIG['host_os'].downcase =~ /mswin|mingw|cygwin/) != nil
|
26
25
|
end
|
27
26
|
|
28
27
|
def initialize(options = {})
|
data/lib/nugrant/parameters.rb
CHANGED
File without changes
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
require 'nugrant/helper/yaml'
|
3
|
+
|
4
|
+
module Nugrant
|
5
|
+
module Vagrant
|
6
|
+
module V1
|
7
|
+
module Command
|
8
|
+
class Parameters < ::Vagrant::Command::Base
|
9
|
+
def initialize(arguments, environment)
|
10
|
+
super(arguments, environment)
|
11
|
+
|
12
|
+
@show_help = false
|
13
|
+
@show_defaults = false
|
14
|
+
@show_system = false
|
15
|
+
@show_user = false
|
16
|
+
@show_project = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_parser()
|
20
|
+
return OptionParser.new do |parser|
|
21
|
+
parser.banner = "Usage: vagrant user parameters [<options>]"
|
22
|
+
parser.separator ""
|
23
|
+
|
24
|
+
parser.separator "Available options:"
|
25
|
+
parser.separator ""
|
26
|
+
|
27
|
+
parser.on("-h", "--help", "Print this help") do
|
28
|
+
@show_help = true
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.on("-d", "--defaults", "Show only defaults parameters") do
|
32
|
+
@show_defaults = true
|
33
|
+
end
|
34
|
+
|
35
|
+
parser.on("-s", "--system", "Show only system parameters") do
|
36
|
+
@show_system = true
|
37
|
+
end
|
38
|
+
|
39
|
+
parser.on("-u", "--user", "Show only user parameters") do
|
40
|
+
@show_user = true
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.on("-p", "--project", "Show only project parameters") do
|
44
|
+
@show_project = true
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.separator ""
|
48
|
+
parser.separator "When no options is provided, the command prints the names and values \n" +
|
49
|
+
"of all parameters that would be available for usage in the Vagrantfile.\n" +
|
50
|
+
"The hierarchy of the parameters is respected, so the final values are\n" +
|
51
|
+
"displayed."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute
|
56
|
+
parser = create_parser()
|
57
|
+
arguments = parse_options(parser)
|
58
|
+
|
59
|
+
return help(parser) if @show_help
|
60
|
+
|
61
|
+
@logger.debug("'Parameters' each target VM...")
|
62
|
+
with_target_vms(arguments) do |vm|
|
63
|
+
parameters = vm.config.keys[:user].parameters
|
64
|
+
|
65
|
+
@env.ui.info("# Vm '#{vm.name}'", :prefix => false)
|
66
|
+
|
67
|
+
defaults(parameters) if @show_defaults
|
68
|
+
system(parameters) if @show_system
|
69
|
+
user(parameters) if @show_user
|
70
|
+
project(parameters) if @show_project
|
71
|
+
|
72
|
+
all(parameters) if !@show_defaults && !@show_system && !@show_user && !@show_project
|
73
|
+
end
|
74
|
+
|
75
|
+
return 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def help(parser)
|
79
|
+
@env.ui.info(parser.help, :prefix => false)
|
80
|
+
end
|
81
|
+
|
82
|
+
def defaults(parameters)
|
83
|
+
print_results("Defaults", parameters.defaults)
|
84
|
+
end
|
85
|
+
|
86
|
+
def system(parameters)
|
87
|
+
print_results("System", parameters.system)
|
88
|
+
end
|
89
|
+
|
90
|
+
def user(parameters)
|
91
|
+
print_results("User", parameters.user)
|
92
|
+
end
|
93
|
+
|
94
|
+
def project(parameters)
|
95
|
+
print_results("Project", parameters.project)
|
96
|
+
end
|
97
|
+
|
98
|
+
def all(parameters)
|
99
|
+
print_results("All", parameters.all)
|
100
|
+
end
|
101
|
+
|
102
|
+
def print_results(kind, parameters)
|
103
|
+
if !parameters || parameters.empty?()
|
104
|
+
print_header(kind)
|
105
|
+
@env.ui.info(" Empty", :prefix => false)
|
106
|
+
@env.ui.info("", :prefix => false)
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
print_parameters(kind, {
|
111
|
+
'config' => {
|
112
|
+
'user' => parameters
|
113
|
+
}
|
114
|
+
})
|
115
|
+
end
|
116
|
+
|
117
|
+
def print_parameters(kind, data)
|
118
|
+
string = Nugrant::Helper::Yaml.format(data.to_yaml, :indent => 1)
|
119
|
+
|
120
|
+
print_header(kind)
|
121
|
+
@env.ui.info(string, :prefix => false)
|
122
|
+
@env.ui.info("", :prefix => false)
|
123
|
+
end
|
124
|
+
|
125
|
+
def print_header(kind, length = 50)
|
126
|
+
@env.ui.info(" #{kind.capitalize} Parameters", :prefix => false)
|
127
|
+
@env.ui.info(" " + "-" * length, :prefix => false)
|
128
|
+
end
|
129
|
+
|
130
|
+
def compute_header_length(string)
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
module Vagrant
|
5
|
+
module V1
|
6
|
+
module Command
|
7
|
+
class Root < ::Vagrant::Command::Base
|
8
|
+
def initialize(arguments, environment)
|
9
|
+
super(arguments, environment)
|
10
|
+
|
11
|
+
@arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments)
|
12
|
+
|
13
|
+
# Change super class available arguments to main ones only
|
14
|
+
@argv = @arguments
|
15
|
+
|
16
|
+
@subcommands = ::Vagrant::Registry.new()
|
17
|
+
@subcommands.register(:parameters) do
|
18
|
+
require File.expand_path("../parameters", __FILE__)
|
19
|
+
Parameters
|
20
|
+
end
|
21
|
+
|
22
|
+
@show_help = false
|
23
|
+
@show_version = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_parser()
|
27
|
+
return OptionParser.new do |parser|
|
28
|
+
parser.banner = "Usage: vagrant user [-h] [-v] <command> [<args>]"
|
29
|
+
|
30
|
+
parser.separator ""
|
31
|
+
parser.on("-h", "--help", "Print this help") do
|
32
|
+
@show_help = true
|
33
|
+
end
|
34
|
+
|
35
|
+
parser.on("-v", "--version", "Print plugin version and exit.") do
|
36
|
+
@show_version = true
|
37
|
+
end
|
38
|
+
|
39
|
+
parser.separator ""
|
40
|
+
parser.separator "Available subcommands:"
|
41
|
+
|
42
|
+
keys = []
|
43
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
44
|
+
|
45
|
+
keys.sort.each do |key|
|
46
|
+
parser.separator " #{key}"
|
47
|
+
end
|
48
|
+
|
49
|
+
parser.separator ""
|
50
|
+
parser.separator "For help on any individual command run `vagrant user COMMAND -h`"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def execute
|
55
|
+
parser = create_parser()
|
56
|
+
arguments = parse_options(parser)
|
57
|
+
|
58
|
+
return version() if @show_version
|
59
|
+
return help(parser) if @show_help
|
60
|
+
|
61
|
+
command_class = @subcommands.get(@subcommand.to_sym) if @subcommand
|
62
|
+
return help(parser) if !command_class || !@subcommand
|
63
|
+
|
64
|
+
@logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}")
|
65
|
+
|
66
|
+
command_class.new(@subarguments, @env).execute
|
67
|
+
end
|
68
|
+
|
69
|
+
def help(parser)
|
70
|
+
@env.ui.info(parser.help, :prefix => false)
|
71
|
+
end
|
72
|
+
|
73
|
+
def version()
|
74
|
+
@env.ui.info("Nugrant version #{Nugrant::VERSION}", :prefix => false)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|