nugrant 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +23 -0
- data/CONTRIBUTORS.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +40 -7
- data/lib/nugrant/config.rb +7 -2
- data/lib/nugrant/helper/env/exporter.rb +6 -6
- data/lib/nugrant/mixin/parameters.rb +16 -0
- data/lib/nugrant/vagrant/v2/action.rb +17 -0
- data/lib/nugrant/vagrant/v2/action/auto_export.rb +45 -0
- data/lib/nugrant/vagrant/v2/command/env.rb +12 -4
- data/lib/nugrant/vagrant/v2/command/parameters.rb +1 -1
- data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +1 -1
- data/lib/nugrant/vagrant/v2/command/root.rb +2 -2
- data/lib/nugrant/vagrant/v2/plugin.rb +11 -1
- data/lib/nugrant/version.rb +1 -1
- metadata +6 -4
- data/DEVELOPMENT.md +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16c6ab3c8e5e927d721709d9ef50c994386f71be
|
4
|
+
data.tar.gz: 5b07b32caedb79df6a879906c302a1512baaccaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 008a2bf813159fd4676e722658aa817589284092d437269501b7316aea71c927cecb5268935b9614b3c6ef152324c2a9e880216670fbe4afc95e77d762abe5c0
|
7
|
+
data.tar.gz: 159c9c629ae3e3db4c6ecbf79754a4108a1fb5e5df51109d33908e1f893c1413d7dbfd40530623cd70c14089fe4cc412f2b1cc427bd04325ada59fe56b984bf8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
# 2.1.0 (November 1st, 2014)
|
2
|
+
|
3
|
+
* Added possibility to specify the script path where to generate
|
4
|
+
the environment commands (export/unset) when using the
|
5
|
+
`vagrant user env` command.
|
6
|
+
|
7
|
+
* Added possibility to automatically export variables on vagrant provision.
|
8
|
+
This can be used by specifying `config.user.auto_export = <format>` in
|
9
|
+
your Vagrantfile where <format> can be one of:
|
10
|
+
|
11
|
+
* `false` => No auto export (default value).
|
12
|
+
* `:autoenv` => Export to [autoenv](https://github.com/kennethreitz/autoenv) script format.
|
13
|
+
* `:script` => Export to a bash script file.
|
14
|
+
* `[:autoenv, :script]` => export both format.
|
15
|
+
|
16
|
+
The default generated script path is "./nugrant2env.sh". You can change
|
17
|
+
the default script name by specifying the configuration key `config.user.auto_export_script_path`
|
18
|
+
in your Vagrantfile:
|
19
|
+
|
20
|
+
config.user.auto_export_script_path = "./script/example.sh"
|
21
|
+
|
22
|
+
Contributed by [@ruifil](https://github.com/ruifil).
|
23
|
+
|
1
24
|
# 2.0.2 (July 13th, 2014)
|
2
25
|
|
3
26
|
* Fixed a bug when using some vagrant commands. The code to retrieve
|
data/CONTRIBUTORS.md
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -438,8 +438,8 @@ Usage:
|
|
438
438
|
##### Env
|
439
439
|
|
440
440
|
Sometimes, you would like to have acces to the different values
|
441
|
-
stored in your `.vagrantuser` from environment variables
|
442
|
-
|
441
|
+
stored in your `.vagrantuser` from environment variables: this is
|
442
|
+
exactly what this section is meant to show you.
|
443
443
|
|
444
444
|
By using one of the three methods below, you will be able to export
|
445
445
|
(but also unset) environment variables from your current
|
@@ -458,10 +458,6 @@ export command:
|
|
458
458
|
|
459
459
|
export DB_USER=root
|
460
460
|
|
461
|
-
And the unset command:
|
462
|
-
|
463
|
-
unset DB_USER
|
464
|
-
|
465
461
|
The value are escaped so it is possible to define value containing
|
466
462
|
spaces for example.
|
467
463
|
|
@@ -473,9 +469,13 @@ would be overwritten by an export command.
|
|
473
469
|
Add flag `-h` (or `--help`) for description of the command and a
|
474
470
|
list of available options.
|
475
471
|
|
472
|
+
It's possible to export variables automatically on when Vagrant
|
473
|
+
provision your VM. Refer to [Automatic Exporting section](#automatic-exporting)
|
474
|
+
for more information.
|
475
|
+
|
476
476
|
###### Method #1
|
477
477
|
|
478
|
-
If you plan to use
|
478
|
+
If you plan to frequently use this feature, our best suggestion
|
479
479
|
is to create a little bash script that will simply delegates
|
480
480
|
to the real command. By having a bash script that calls the
|
481
481
|
command, you will be able to easily export environment variables
|
@@ -546,6 +546,39 @@ available in your environment.
|
|
546
546
|
Using `vagrant user env -u --format autoenv` will instead generate
|
547
547
|
the autoenv file that will unset the environment variables.
|
548
548
|
|
549
|
+
#### Automatic Exporting
|
550
|
+
|
551
|
+
Running the right command each time variables change can be repetive
|
552
|
+
for nothing. Why not let the computer do the hard work for us, they
|
553
|
+
have been created for this after all.
|
554
|
+
|
555
|
+
You can achieve this using the `config.user.auto_export` parameter.
|
556
|
+
Defaulting to `false`, you can use it to export the variables
|
557
|
+
to your desired format. When set to a valid value, each time
|
558
|
+
vagrant will provision your VM, Nugrant will automatically
|
559
|
+
export variables for your.
|
560
|
+
|
561
|
+
Use the following configuration to export to [autoenv](https://github.com/kennethreitz/autoenv)
|
562
|
+
script format.
|
563
|
+
|
564
|
+
config.user.auto_export = :autoenv
|
565
|
+
|
566
|
+
Use the following configuration to export to bash script.
|
567
|
+
|
568
|
+
config.user.auto_export = :script
|
569
|
+
|
570
|
+
You can also pass an array of formats if you would like to export to
|
571
|
+
multiple formats at the same time.
|
572
|
+
|
573
|
+
config.user.auto_export = [:autoenv, :script]
|
574
|
+
|
575
|
+
|
576
|
+
The default filename for bash script (i.e. when using `:script` value) is
|
577
|
+
`./nugrant2env.sh`. You can control this by using parameter
|
578
|
+
`config.user.auto_export_script_path`:
|
579
|
+
|
580
|
+
config.user.auto_export_script_path = "./script/env.sh"
|
581
|
+
|
549
582
|
### Library
|
550
583
|
|
551
584
|
Using Nugrant as a library to handle parameters from various
|
data/lib/nugrant/config.rb
CHANGED
@@ -5,16 +5,17 @@ module Nugrant
|
|
5
5
|
DEFAULT_ARRAY_MERGE_STRATEGY = :replace
|
6
6
|
DEFAULT_PARAMS_FILENAME = ".nuparams"
|
7
7
|
DEFAULT_PARAMS_FORMAT = :yaml
|
8
|
+
DEFAULT_AUTO_EXPORT = false
|
8
9
|
|
9
10
|
SUPPORTED_ARRAY_MERGE_STRATEGIES = [:concat, :extend, :replace]
|
10
11
|
SUPPORTED_PARAMS_FORMATS = [:json, :yaml]
|
11
12
|
|
12
13
|
attr_reader :params_filename, :params_format,
|
13
14
|
:current_path, :user_path, :system_path,
|
14
|
-
:array_merge_strategy,
|
15
|
+
:array_merge_strategy, :auto_export, :auto_export_script_path,
|
15
16
|
:key_error, :parse_error
|
16
17
|
|
17
|
-
attr_writer :array_merge_strategy
|
18
|
+
attr_writer :array_merge_strategy, :auto_export, :auto_export_script_path
|
18
19
|
|
19
20
|
##
|
20
21
|
# Convenience method to easily accept either a hash that will
|
@@ -127,10 +128,14 @@ module Nugrant
|
|
127
128
|
# the error object, that deal with the error. If the callable does not
|
128
129
|
# raise an exception, the result of it's execution is returned.
|
129
130
|
# Defaults => A callable that returns the empty hash.
|
131
|
+
# * +:auto_export+ - Automatically export configuration to the specified format :autoenv or :script
|
132
|
+
# * +:auto_export_script_path+ - The path where to write the export script, defaults to "./nugrant2env.sh"
|
130
133
|
#
|
131
134
|
def initialize(options = {})
|
132
135
|
@params_filename = options[:params_filename] || DEFAULT_PARAMS_FILENAME
|
133
136
|
@params_format = options[:params_format] || DEFAULT_PARAMS_FORMAT
|
137
|
+
@auto_export = options[:auto_export] || DEFAULT_AUTO_EXPORT
|
138
|
+
@auto_export_script_path = options[:auto_export_script_path] || false # use default
|
134
139
|
|
135
140
|
@current_path = Config.fixup_path(options[:current_path], ".", @params_filename)
|
136
141
|
@user_path = Config.fixup_path(options[:user_path], Config.default_user_path(), @params_filename)
|
@@ -7,10 +7,10 @@ module Nugrant
|
|
7
7
|
module Helper
|
8
8
|
module Env
|
9
9
|
module Exporter
|
10
|
-
|
11
|
-
|
10
|
+
DEFAULT_AUTOENV_PATH = "./.env"
|
11
|
+
DEFAULT_SCRIPT_PATH = "./nugrant2env.sh"
|
12
12
|
|
13
|
-
|
13
|
+
VALID_EXPORTERS = [:autoenv, :script, :terminal]
|
14
14
|
|
15
15
|
##
|
16
16
|
# Returns true if the exporter name received is a valid
|
@@ -20,7 +20,7 @@ module Nugrant
|
|
20
20
|
#
|
21
21
|
# @return true if exporter is valid, false otherwise.
|
22
22
|
def self.valid?(exporter)
|
23
|
-
|
23
|
+
VALID_EXPORTERS.include?(exporter)
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
@@ -43,7 +43,7 @@ module Nugrant
|
|
43
43
|
# * :type => The type of command, default to :export.
|
44
44
|
#
|
45
45
|
def self.autoenv_exporter(bag, options = {})
|
46
|
-
io = options[:io] || (File.open(File.expand_path(options[:autoenv_path] ||
|
46
|
+
io = options[:io] || (File.open(File.expand_path(options[:autoenv_path] || DEFAULT_AUTOENV_PATH), "w"))
|
47
47
|
|
48
48
|
terminal_exporter(bag, options.merge({:io => io}))
|
49
49
|
ensure
|
@@ -70,7 +70,7 @@ module Nugrant
|
|
70
70
|
# * :type => The type of command, default to :export.
|
71
71
|
#
|
72
72
|
def self.script_exporter(bag, options = {})
|
73
|
-
io = options[:io] || (File.open(File.expand_path(options[:script_path] ||
|
73
|
+
io = options[:io] || (File.open(File.expand_path(options[:script_path] || DEFAULT_SCRIPT_PATH), "w"))
|
74
74
|
|
75
75
|
io.puts("#!/bin/env sh")
|
76
76
|
io.puts()
|
@@ -48,6 +48,14 @@ module Nugrant
|
|
48
48
|
@__config.array_merge_strategy
|
49
49
|
end
|
50
50
|
|
51
|
+
def auto_export
|
52
|
+
@__config.auto_export
|
53
|
+
end
|
54
|
+
|
55
|
+
def auto_export_script_path
|
56
|
+
@__config.auto_export_script_path
|
57
|
+
end
|
58
|
+
|
51
59
|
##
|
52
60
|
# Change the current array merge strategy for this parameters.
|
53
61
|
#
|
@@ -61,6 +69,14 @@ module Nugrant
|
|
61
69
|
compute_all!()
|
62
70
|
end
|
63
71
|
|
72
|
+
def auto_export=(auto_export)
|
73
|
+
@__config.auto_export = auto_export
|
74
|
+
end
|
75
|
+
|
76
|
+
def auto_export_script_path=(path)
|
77
|
+
@__config.auto_export_script_path = path
|
78
|
+
end
|
79
|
+
|
64
80
|
def defaults()
|
65
81
|
@__defaults
|
66
82
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'nugrant/vagrant/v2/action/auto_export'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
module Vagrant
|
5
|
+
module V2
|
6
|
+
module Action
|
7
|
+
class << self
|
8
|
+
def auto_export
|
9
|
+
@auto_export ||= ::Vagrant::Action::Builder.new.tap do |builder|
|
10
|
+
builder.use Nugrant::Vagrant::V2::Action::AutoExport
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'nugrant'
|
2
|
+
require 'nugrant/helper/env/exporter'
|
3
|
+
require 'nugrant/parameters'
|
4
|
+
|
5
|
+
EnvExporter = Nugrant::Helper::Env::Exporter
|
6
|
+
|
7
|
+
module Nugrant
|
8
|
+
module Vagrant
|
9
|
+
module V2
|
10
|
+
module Action
|
11
|
+
class AutoExport
|
12
|
+
def initialize(app, env)
|
13
|
+
@app = app
|
14
|
+
@config = env[:machine].env.vagrantfile.config
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
return @app.call(env) if not @config.user.auto_export
|
19
|
+
|
20
|
+
options = {
|
21
|
+
:type => :export,
|
22
|
+
:script_path => @config.user.auto_export_script_path
|
23
|
+
}
|
24
|
+
|
25
|
+
Array(@config.user.auto_export).each do |exporter|
|
26
|
+
if exporter == :terminal or not EnvExporter.valid?(exporter)
|
27
|
+
env[:ui].warn("ERROR: Invalid config.user.auto_export value '#{format}'", :prefix => false)
|
28
|
+
next
|
29
|
+
end
|
30
|
+
|
31
|
+
env[:ui].info("Configuration exported '#{format}'", :prefix => false)
|
32
|
+
|
33
|
+
case
|
34
|
+
when format == :script
|
35
|
+
EnvExporter.script_exporter(@config.user.__all, options)
|
36
|
+
when format == :autoenv
|
37
|
+
EnvExporter.autoenv_exporter(@config.user.__all, options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -18,6 +18,7 @@ module Nugrant
|
|
18
18
|
|
19
19
|
@unset = false
|
20
20
|
@format = :terminal
|
21
|
+
@script_path = false
|
21
22
|
@show_help = false
|
22
23
|
end
|
23
24
|
|
@@ -43,15 +44,19 @@ module Nugrant
|
|
43
44
|
parser.separator "Available options:"
|
44
45
|
parser.separator ""
|
45
46
|
|
46
|
-
parser.on("-u", "--
|
47
|
-
@unset =
|
47
|
+
parser.on("-u", "--unset", "Generates commands needed to unset environment variables, default false") do
|
48
|
+
@unset = true
|
48
49
|
end
|
49
50
|
|
50
51
|
parser.on("-f", "--format FORMAT", "Determines in what format variables are output, default to terminal") do |format|
|
51
52
|
@format = format.to_sym()
|
52
53
|
end
|
53
54
|
|
54
|
-
parser.on("-
|
55
|
+
parser.on("-s", "--script-path PATH", "Specifies path of the generated bash script, default to #{EnvExporter::DEFAULT_SCRIPT_PATH}") do |path|
|
56
|
+
@script_path = path
|
57
|
+
end
|
58
|
+
|
59
|
+
parser.on("-h", "--help", "Prints this help") do
|
55
60
|
@show_help = true
|
56
61
|
end
|
57
62
|
end
|
@@ -87,7 +92,10 @@ module Nugrant
|
|
87
92
|
|
88
93
|
bag = parameters.__all
|
89
94
|
|
90
|
-
options = {
|
95
|
+
options = {
|
96
|
+
:type => @unset ? :unset : :export,
|
97
|
+
:script_path => @script_path
|
98
|
+
}
|
91
99
|
|
92
100
|
case
|
93
101
|
when @format == :script
|
@@ -43,11 +43,11 @@ module Nugrant
|
|
43
43
|
parser.banner = "Usage: vagrant user [-h] [-v] <subcommand> [<args>]"
|
44
44
|
|
45
45
|
parser.separator ""
|
46
|
-
parser.on("-h", "--help", "
|
46
|
+
parser.on("-h", "--help", "Prints this help") do
|
47
47
|
@show_help = true
|
48
48
|
end
|
49
49
|
|
50
|
-
parser.on("-v", "--version", "
|
50
|
+
parser.on("-v", "--version", "Prints plugin version and exit.") do
|
51
51
|
@show_version = true
|
52
52
|
end
|
53
53
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'nugrant/vagrant/v2/action'
|
1
2
|
|
2
3
|
module Nugrant
|
3
4
|
module Vagrant
|
@@ -8,6 +9,16 @@ module Nugrant
|
|
8
9
|
Plugin to define and use user specific parameters from various location inside your Vagrantfile.
|
9
10
|
DESC
|
10
11
|
|
12
|
+
class << self
|
13
|
+
def provision(hook)
|
14
|
+
hook.before(::Vagrant::Action::Builtin::Provision, Nugrant::Vagrant::V2::Action.auto_export)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
action_hook(:nugrant_provision, :machine_action_up, &method(:provision))
|
19
|
+
action_hook(:nugrant_provision, :machine_action_reload, &method(:provision))
|
20
|
+
action_hook(:nugrant_provision, :machine_action_provision, &method(:provision))
|
21
|
+
|
11
22
|
command "user" do
|
12
23
|
require_relative "command/root"
|
13
24
|
Command::Root
|
@@ -21,4 +32,3 @@ module Nugrant
|
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
24
|
-
|
data/lib/nugrant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nugrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Vachon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -46,7 +46,7 @@ files:
|
|
46
46
|
- .project
|
47
47
|
- .travis.yml
|
48
48
|
- CHANGELOG.md
|
49
|
-
-
|
49
|
+
- CONTRIBUTORS.md
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE.txt
|
52
52
|
- README.md
|
@@ -63,6 +63,8 @@ files:
|
|
63
63
|
- lib/nugrant/mixin/parameters.rb
|
64
64
|
- lib/nugrant/parameters.rb
|
65
65
|
- lib/nugrant/vagrant/errors.rb
|
66
|
+
- lib/nugrant/vagrant/v2/action.rb
|
67
|
+
- lib/nugrant/vagrant/v2/action/auto_export.rb
|
66
68
|
- lib/nugrant/vagrant/v2/command/env.rb
|
67
69
|
- lib/nugrant/vagrant/v2/command/parameters.rb
|
68
70
|
- lib/nugrant/vagrant/v2/command/restricted_keys.rb
|
@@ -145,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
147
|
version: '0'
|
146
148
|
requirements: []
|
147
149
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.2.2
|
149
151
|
signing_key:
|
150
152
|
specification_version: 4
|
151
153
|
summary: Library to handle user specific parameters from various location.
|
data/DEVELOPMENT.md
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# Nugrant [![Build Status](https://travis-ci.org/maoueh/nugrant.png)](https://travis-ci.org/maoueh/nugrant)
|
2
|
-
|
3
|
-
Since at first I wanted to have support for plugin api V1 and V2 in the same
|
4
|
-
codebase without having to switch between branches, development is a bit
|
5
|
-
more complicated than usual.
|
6
|
-
|
7
|
-
As many other ruby projects, Nugrant use `bundler` to manage its dependencies.
|
8
|
-
However, as not many ruby projects, Nugrant supports two incompatible version
|
9
|
-
of Vagrant.
|
10
|
-
|
11
|
-
For this reason, the `Gemfile` used by `bundler` is conditional to an
|
12
|
-
environment variable. The environment used is `VAGRANT_PLUGIN_VERSION`.
|
13
|
-
When it is set, it can take the value `v1` or `v2` which is the plugin
|
14
|
-
version you want to test. By default, if the environment variable is
|
15
|
-
not set, `v2` is the default.
|
16
|
-
|
17
|
-
## Develop Nugrant for Vagrant api v1
|
18
|
-
|
19
|
-
To do this, you will need to set and environment variable
|
20
|
-
`VAGRANT_PLUGIN_VERSION` to `v1` prior to calling bundle
|
21
|
-
install, like this:
|
22
|
-
|
23
|
-
VAGRANT_PLUGIN_VERSION="v1" bundle install
|
24
|
-
|
25
|
-
This will instruct `bundler` to setup Vagrant `1.0.z`, which
|
26
|
-
at the time of talking, is `1.0.7`.
|
27
|
-
|
28
|
-
## Develop Nugrant for Vagrant api v2
|
29
|
-
|
30
|
-
You can simply install the dependencies normally by doing:
|
31
|
-
|
32
|
-
bundle install
|
33
|
-
|
34
|
-
|