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.
@@ -0,0 +1,33 @@
1
+ require 'nugrant'
2
+
3
+ module Nugrant
4
+ module Vagrant
5
+ module V1
6
+ module Config
7
+ class User < ::Vagrant::Config::Base
8
+ attr_reader :parameters
9
+
10
+ def initialize()
11
+ @parameters = Nugrant::Parameters.new()
12
+ end
13
+
14
+ def [](param_name)
15
+ return @parameters[param_name]
16
+ end
17
+
18
+ def method_missing(method, *args, &block)
19
+ return @parameters.method_missing(method, *args, &block)
20
+ end
21
+
22
+ def defaults(parameters)
23
+ @parameters.defaults(parameters)
24
+ end
25
+
26
+ def defaults=(parameters)
27
+ @parameters.defaults=(parameters)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ require 'nugrant/vagrant/v1/command/root'
2
+ require 'nugrant/vagrant/v1/config/user'
3
+
4
+ # Plugin bootstrap
5
+ Vagrant.commands.register(:user) { Nugrant::Vagrant::V1::Command::Root }
6
+ Vagrant.config_keys.register(:user) { Nugrant::Vagrant::V1::Config::User }
@@ -0,0 +1,137 @@
1
+ require 'nugrant'
2
+ require 'nugrant/helper/yaml'
3
+
4
+ module Nugrant
5
+ module Vagrant
6
+ module V2
7
+ module Command
8
+ class Parameters < ::Vagrant.plugin("2", :command)
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.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,81 @@
1
+ require 'nugrant'
2
+ require 'nugrant/version'
3
+
4
+ module Nugrant
5
+ module Vagrant
6
+ module V2
7
+ module Command
8
+ class Root < ::Vagrant.plugin("2", :command)
9
+ def initialize(arguments, environment)
10
+ super(arguments, environment)
11
+
12
+ @arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments)
13
+
14
+ # Change super class available arguments to main ones only
15
+ @argv = @arguments
16
+
17
+ @subcommands = ::Vagrant::Registry.new()
18
+ @subcommands.register(:parameters) do
19
+ require File.expand_path("../parameters", __FILE__)
20
+ Parameters
21
+ end
22
+
23
+ @show_help = false
24
+ @show_version = false
25
+ end
26
+
27
+ def create_parser()
28
+ return OptionParser.new do |parser|
29
+ parser.banner = "Usage: vagrant user [-h] [-v] <command> [<args>]"
30
+
31
+ parser.separator ""
32
+ parser.on("-h", "--help", "Print this help") do
33
+ @show_help = true
34
+ end
35
+
36
+ parser.on("-v", "--version", "Print plugin version and exit.") do
37
+ @show_version = true
38
+ end
39
+
40
+ parser.separator ""
41
+ parser.separator "Available subcommands:"
42
+
43
+ keys = []
44
+ @subcommands.each { |key, value| keys << key.to_s }
45
+
46
+ keys.sort.each do |key|
47
+ parser.separator " #{key}"
48
+ end
49
+
50
+ parser.separator ""
51
+ parser.separator "For help on any individual command run `vagrant user COMMAND -h`"
52
+ end
53
+ end
54
+
55
+ def execute
56
+ parser = create_parser()
57
+ arguments = parse_options(parser)
58
+
59
+ return version() if @show_version
60
+ return help(parser) if @show_help
61
+
62
+ command_class = @subcommands.get(@subcommand.to_sym) if @subcommand
63
+ return help(parser) if !command_class || !@subcommand
64
+
65
+ @logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}")
66
+
67
+ command_class.new(@subarguments, @env).execute
68
+ end
69
+
70
+ def help(parser)
71
+ @env.ui.info(parser.help, :prefix => false)
72
+ end
73
+
74
+ def version()
75
+ @env.ui.info("Nugrant version #{Nugrant::VERSION}", :prefix => false)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,33 @@
1
+ require 'nugrant'
2
+
3
+ module Nugrant
4
+ module Vagrant
5
+ module V2
6
+ module Config
7
+ class User < ::Vagrant.plugin("2", :config)
8
+ attr_reader :parameters
9
+
10
+ def initialize()
11
+ @parameters = Nugrant::Parameters.new()
12
+ end
13
+
14
+ def [](param_name)
15
+ return @parameters[param_name]
16
+ end
17
+
18
+ def method_missing(method, *args, &block)
19
+ return @parameters.method_missing(method, *args, &block)
20
+ end
21
+
22
+ def defaults(parameters)
23
+ @parameters.defaults(parameters)
24
+ end
25
+
26
+ def defaults=(parameters)
27
+ @parameters.defaults=(parameters)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+
2
+ module Nugrant
3
+ module Vagrant
4
+ module V2
5
+ class Plugin < ::Vagrant.plugin("2")
6
+ name "Nugrant"
7
+
8
+ command "user" do
9
+ require_relative "command/root"
10
+
11
+ Command::Root
12
+ end
13
+
14
+ config "user" do
15
+ require_relative "config/user"
16
+ Config::User
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -1,3 +1,3 @@
1
1
  module Nugrant
2
- VERSION = "0.0.14"
2
+ VERSION = "1.0.0.pre1"
3
3
  end
data/lib/vagrant_init.rb CHANGED
@@ -1,7 +1,2 @@
1
1
  # This module will initialize the vagrant plugin
2
- require 'nugrant/vagrant/command/root'
3
- require 'nugrant/vagrant/config/user'
4
-
5
- # Plugin bootstrap
6
- Vagrant.commands.register(:user) { Nugrant::Vagrant::Command::Root }
7
- Vagrant.config_keys.register(:user) { Nugrant::Vagrant::Config::User }
2
+ require "nugrant/vagrant/v1/plugin"
data/nugrant.gemspec CHANGED
@@ -10,13 +10,17 @@ Gem::Specification.new do |gem|
10
10
  gem.authors = ["Matthieu Vachon"]
11
11
  gem.email = ["matthieu.o.vachon@gmail.com"]
12
12
  gem.homepage = "https://github.com/maoueh/nugrant"
13
- gem.summary = "Vagrant plugin to enable user specific configuration parameters."
13
+ gem.summary = "Library to handle user specific parameters from various location."
14
14
  gem.description = <<-EOF
15
- This gem is in fact a Vagrant plugin. By installing this gem, it will be
16
- possible to define user specific configuration files that will be merge
17
- directly into the Vagrant configuration. This is useful if you need to
18
- share a Vagrantfile to multiple developers but would like to customize
19
- some parameters for each users differently.
15
+ Nugrant is a library to easily handle parameters that need to be
16
+ injected into an application via different sources (system, user,
17
+ project, defaults).
18
+
19
+ Nugrant can also be directly used as a Vagrant plugin. By activating
20
+ this gem with Vagrant, it will be possible to define user specific
21
+ parameters that will be injected directly into the Vagrantfile. This
22
+ is useful if you need to share a Vagrantfile to multiple developers
23
+ but would like to customize some parameters for each user differently.
20
24
  EOF
21
25
 
22
26
  gem.files = `git ls-files`.split($/)
@@ -26,6 +30,5 @@ Gem::Specification.new do |gem|
26
30
 
27
31
  gem.add_dependency "deep_merge", "~> 1.0.0"
28
32
 
29
- gem.add_development_dependency "rake", "~> 0.9.0"
30
- gem.add_development_dependency "vagrant", "~> 1.0.5"
33
+ gem.add_development_dependency "rake"
31
34
  end
@@ -0,0 +1,9 @@
1
+ Vagrant::Config.run do |config|
2
+ config.user.defaults = {
3
+ 'value' => "test"
4
+ }
5
+
6
+ config.vm.box = "testing"
7
+
8
+ puts config.user.value
9
+ end
@@ -0,0 +1,19 @@
1
+ Vagrant::Config.run do |config|
2
+ config.vm.box = "base"
3
+ config.vm.box_url = "http://domain.com/path/to/above.box"
4
+
5
+ config.vm.network :forwarded_port, guest: 80, host: 8080
6
+
7
+ config.vm.shared_folder "C:/Users/Matt/nugrant", "/vagrant_data"
8
+
9
+ config.vm.customize ["modifyvm", :id, "--memory", "256"]
10
+
11
+ config.vm.provision :chef_solo do |chef|
12
+ chef.cookbooks_path = "C:\Users\Matt\Work\kitchen\cookbooks"
13
+ chef.roles_path = "C:\Users\Matt\Work\kitchen\roles"
14
+ chef.nodes_path = "C:\Users\Matt\Work\kitchen\nodes"
15
+
16
+ chef.add_recipe "mysql"
17
+ chef.add_role "web"
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.user.defaults = {
3
+ 'value' => "test"
4
+ }
5
+
6
+ config.vm.box = "testing"
7
+
8
+ puts config.user.value
9
+ end
@@ -0,0 +1,22 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.box = "base"
3
+ config.vm.box_url = "http://domain.com/path/to/above.box"
4
+
5
+ config.vm.network :forwarded_port, guest: 80, host: 8080
6
+ config.vm.network :private_network, ip: "10.0.0.2"
7
+
8
+ config.vm.synced_folder "C:/Users/Matt/nugrant", "/vagrant_data"
9
+
10
+ config.vm.provider :virtualbox do |virtualbox|
11
+ virtualbox.customize ["modifyvm", :id, "--memory", "256"]
12
+ end
13
+
14
+ config.vm.provision :chef_solo do |chef|
15
+ chef.cookbooks_path = "C:\Users\Matt\Work\kitchen\cookbooks"
16
+ chef.roles_path = "C:\Users\Matt\Work\kitchen\roles"
17
+ chef.nodes_path = "C:\Users\Matt\Work\kitchen\nodes"
18
+
19
+ chef.add_recipe "mysql"
20
+ chef.add_role "web"
21
+ end
22
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nugrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
5
- prerelease:
4
+ version: 1.0.0.pre1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthieu Vachon
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deep_merge
@@ -32,38 +32,24 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.9.0
37
+ version: '0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.9.0
46
- - !ruby/object:Gem::Dependency
47
- name: vagrant
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
43
+ - - ! '>='
52
44
  - !ruby/object:Gem::Version
53
- version: 1.0.5
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.0.5
62
- description: ! " This gem is in fact a Vagrant plugin. By installing this gem,
63
- it will be\n possible to define user specific configuration files that will
64
- be merge\n directly into the Vagrant configuration. This is useful if you need
65
- to\n share a Vagrantfile to multiple developers but would like to customize\n
66
- \ some parameters for each users differently.\n"
45
+ version: '0'
46
+ description: ! " Nugrant is a library to easily handle parameters that need to
47
+ be\n injected into an application via different sources (system, user,\n project,
48
+ defaults).\n\n Nugrant can also be directly used as a Vagrant plugin. By activating\n
49
+ \ this gem with Vagrant, it will be possible to define user specific\n parameters
50
+ that will be injected directly into the Vagrantfile. This\n is useful if you
51
+ need to share a Vagrantfile to multiple developers\n but would like to customize
52
+ some parameters for each user differently.\n"
67
53
  email:
68
54
  - matthieu.o.vachon@gmail.com
69
55
  executables: []
@@ -85,9 +71,14 @@ files:
85
71
  - lib/nugrant/config.rb
86
72
  - lib/nugrant/helper/yaml.rb
87
73
  - lib/nugrant/parameters.rb
88
- - lib/nugrant/vagrant/command/parameters.rb
89
- - lib/nugrant/vagrant/command/root.rb
90
- - lib/nugrant/vagrant/config/user.rb
74
+ - lib/nugrant/vagrant/v1/command/parameters.rb
75
+ - lib/nugrant/vagrant/v1/command/root.rb
76
+ - lib/nugrant/vagrant/v1/config/user.rb
77
+ - lib/nugrant/vagrant/v1/plugin.rb
78
+ - lib/nugrant/vagrant/v2/command/parameters.rb
79
+ - lib/nugrant/vagrant/v2/command/root.rb
80
+ - lib/nugrant/vagrant/v2/config/user.rb
81
+ - lib/nugrant/vagrant/v2/plugin.rb
91
82
  - lib/nugrant/version.rb
92
83
  - lib/vagrant_init.rb
93
84
  - nugrant.gemspec
@@ -96,7 +87,10 @@ files:
96
87
  - test/lib/nugrant/test_parameters_bag.rb
97
88
  - test/resources/.vagrantuser
98
89
  - test/resources/README.md
99
- - test/resources/Vagrantfile
90
+ - test/resources/Vagrantfile.v1.fake
91
+ - test/resources/Vagrantfile.v1.real
92
+ - test/resources/Vagrantfile.v2.fake
93
+ - test/resources/Vagrantfile.v2.real
100
94
  - test/resources/json/params_boolean.json
101
95
  - test/resources/json/params_combinations.json
102
96
  - test/resources/json/params_defaults_at_root.json
@@ -141,29 +135,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
135
  version: '0'
142
136
  segments:
143
137
  - 0
144
- hash: 2259077300766997655
138
+ hash: -870213585
145
139
  required_rubygems_version: !ruby/object:Gem::Requirement
146
140
  none: false
147
141
  requirements:
148
- - - ! '>='
142
+ - - ! '>'
149
143
  - !ruby/object:Gem::Version
150
- version: '0'
151
- segments:
152
- - 0
153
- hash: 2259077300766997655
144
+ version: 1.3.1
154
145
  requirements: []
155
146
  rubyforge_project:
156
147
  rubygems_version: 1.8.24
157
148
  signing_key:
158
149
  specification_version: 3
159
- summary: Vagrant plugin to enable user specific configuration parameters.
150
+ summary: Library to handle user specific parameters from various location.
160
151
  test_files:
161
152
  - test/lib/nugrant/test_config.rb
162
153
  - test/lib/nugrant/test_parameters.rb
163
154
  - test/lib/nugrant/test_parameters_bag.rb
164
155
  - test/resources/.vagrantuser
165
156
  - test/resources/README.md
166
- - test/resources/Vagrantfile
157
+ - test/resources/Vagrantfile.v1.fake
158
+ - test/resources/Vagrantfile.v1.real
159
+ - test/resources/Vagrantfile.v2.fake
160
+ - test/resources/Vagrantfile.v2.real
167
161
  - test/resources/json/params_boolean.json
168
162
  - test/resources/json/params_combinations.json
169
163
  - test/resources/json/params_defaults_at_root.json