vagrant-devcommands 0.12.0 → 0.13.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +25 -6
- data/lib/vagrant/devcommands.rb +1 -0
- data/lib/vagrant/devcommands/model/command.rb +5 -100
- data/lib/vagrant/devcommands/param_parser.rb +130 -0
- data/lib/vagrant/devcommands/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 752833dc9227565eb5c6f9e3c9b2a2879aa4042af9ce6be42025efe6509e132b
|
4
|
+
data.tar.gz: a177ba8899bfc7eb2b72c227a30dfcbe8c7317369ccfdc474d6f3082fec3be28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c515bc5e4c2568f6fcc3a98b9389a345aff32bf56507be78f4653dda45d84d4887730a33e96c5e8a5bc58d98775dae7f7aed1f5a95ab4cb84359ab36953d90
|
7
|
+
data.tar.gz: 3af910e8e9e666ae68caa24faba6e79417aac33cf39086d568bc42404292d0501e42e9d69a132da27c9eec064beff4e21eacaa4e6a22d3049b03be7dafe1c80a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.13.0 (2018-07-19)
|
4
|
+
|
5
|
+
- Enhancements
|
6
|
+
- Unknown parameters can be catched and used by setting
|
7
|
+
the option `passthru: true` on one of your parameters
|
8
|
+
([#3](https://github.com/mneudert/vagrant-devcommands/issues/3))
|
9
|
+
|
3
10
|
## v0.12.0 (2018-04-21)
|
4
11
|
|
5
12
|
- Enhancements
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
Runs vagrant commands from a Commandfile.
|
4
4
|
|
5
|
-
|
6
5
|
## Usage
|
7
6
|
|
8
7
|
### Command Listing
|
@@ -86,9 +85,21 @@ command 'with_param',
|
|
86
85
|
# parameters with a limited set of allowed values
|
87
86
|
# the allowed values are checked prior to escaping/wrapping!
|
88
87
|
# optional parameters are only validated if given!
|
89
|
-
p_limited: { allowed: ['completely'] }
|
88
|
+
p_limited: { allowed: ['completely'] },
|
89
|
+
|
90
|
+
# you can define a specific parameter to receive
|
91
|
+
# all otherwise unknown parameters and flags
|
92
|
+
p_passthru: { optional: true, passthru: true }
|
90
93
|
},
|
91
|
-
script:
|
94
|
+
script: %(
|
95
|
+
echo %<p_mandatory>s \
|
96
|
+
%<p_default>s \
|
97
|
+
%<p_escaped>s \
|
98
|
+
%<p_optional>s \
|
99
|
+
%<p_wrapped>s \
|
100
|
+
%<p_limited>s \
|
101
|
+
%<p_passthru>s
|
102
|
+
)
|
92
103
|
```
|
93
104
|
|
94
105
|
This allows you to execute the following command:
|
@@ -105,7 +116,7 @@ vagrant run with_param \
|
|
105
116
|
--p_mandatory works \
|
106
117
|
--p_default sometimes \
|
107
118
|
--p_optional 'like a charm' \
|
108
|
-
--p_wrapped is
|
119
|
+
--p_wrapped is \
|
109
120
|
--p_limited completely
|
110
121
|
```
|
111
122
|
|
@@ -172,7 +183,6 @@ command 'interactive', tty: true
|
|
172
183
|
|
173
184
|
This allows full interaction with programs like `irb` or `mysql`.
|
174
185
|
|
175
|
-
|
176
186
|
### Global Command Definitions
|
177
187
|
|
178
188
|
To have commands available even wihout a `Commandfile` you can define the
|
@@ -340,7 +350,6 @@ vagrant run completion-data
|
|
340
350
|
vagrant run completion-data my-command
|
341
351
|
```
|
342
352
|
|
343
|
-
|
344
353
|
## Notes for Windows Users
|
345
354
|
|
346
355
|
### SSH
|
@@ -369,6 +378,16 @@ It might also help to double check the line endings in your Commandfile are set
|
|
369
378
|
unix-style (`\n`) and not windows-style (`\r\n`) if you get errors when running
|
370
379
|
your commands.
|
371
380
|
|
381
|
+
## Development
|
382
|
+
|
383
|
+
You can always install the plugin directly from source:
|
384
|
+
|
385
|
+
```shell
|
386
|
+
gem build vagrant-devcommands.gemspec
|
387
|
+
|
388
|
+
vagrant plugin uninstall vagrant-devcommands
|
389
|
+
vagrant plugin install vagrant-devcommands-x.x.x.dev.gem
|
390
|
+
```
|
372
391
|
|
373
392
|
## License
|
374
393
|
|
data/lib/vagrant/devcommands.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
1
|
module VagrantPlugins
|
4
2
|
module DevCommands
|
5
3
|
module Model
|
6
4
|
# Definition of an executable command
|
7
5
|
class Command
|
6
|
+
PARAM_PARSER = VagrantPlugins::DevCommands::ParamParser
|
7
|
+
|
8
8
|
attr_reader :name
|
9
9
|
|
10
10
|
attr_reader :flags
|
@@ -35,105 +35,10 @@ module VagrantPlugins
|
|
35
35
|
script = @script
|
36
36
|
script = script.call if script.is_a?(Proc)
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
(script % opts).strip
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def escape_parameters(params)
|
47
|
-
@parameters.each do |key, conf|
|
48
|
-
next if conf[:escape].nil?
|
49
|
-
|
50
|
-
conf[:escape].each do |char, with|
|
51
|
-
char = char.to_s unless char.is_a?(String)
|
52
|
-
params[key] = params[key].sub(char, "#{with}#{char}")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
params
|
57
|
-
end
|
58
|
-
|
59
|
-
def parameters_with_defaults
|
60
|
-
params = {}
|
61
|
-
|
62
|
-
@parameters.each do |key, conf|
|
63
|
-
params[key] = '' if conf[:optional]
|
64
|
-
params[key] = conf[:default] unless conf[:default].nil?
|
65
|
-
end
|
66
|
-
|
67
|
-
params
|
68
|
-
end
|
69
|
-
|
70
|
-
# rubocop:disable Metrics/MethodLength
|
71
|
-
def parse_argv(argv)
|
72
|
-
params = parameters_with_defaults
|
73
|
-
|
74
|
-
OptionParser.new do |opts|
|
75
|
-
@flags.each do |key, conf|
|
76
|
-
params[key] = ''
|
77
|
-
|
78
|
-
opts.on("--#{key}", "Flag: #{key}") do
|
79
|
-
params[key] = conf[:value] || "--#{key}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
@parameters.each_key do |key|
|
84
|
-
opts.on("--#{key} OPTION", "Parameter: #{key}") do |o|
|
85
|
-
params[key] = o
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end.parse!(argv)
|
89
|
-
|
90
|
-
params = unalias_parameters(params)
|
91
|
-
params = validate_parameters(params)
|
92
|
-
params = escape_parameters(params)
|
93
|
-
params = wrap_parameters(params)
|
94
|
-
params
|
95
|
-
end
|
96
|
-
# rubocop:enable Metrics/MethodLength
|
97
|
-
|
98
|
-
def unalias_parameters(params)
|
99
|
-
@parameters.each do |key, conf|
|
100
|
-
next if params[key].nil?
|
101
|
-
next if conf[:aliases].nil?
|
102
|
-
|
103
|
-
conf[:aliases].each do |input, output|
|
104
|
-
params[key] = params[key] == input ? output : params[key]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
params
|
109
|
-
end
|
110
|
-
|
111
|
-
def validate_parameters(params)
|
112
|
-
@parameters.each do |key, conf|
|
113
|
-
next if params[key].nil?
|
114
|
-
next if params[key] == '' && conf[:optional]
|
115
|
-
|
116
|
-
next if conf[:allowed].nil?
|
117
|
-
next if conf[:allowed].include?(params[key])
|
118
|
-
|
119
|
-
raise ArgumentError, "--#{key}=#{params[key]}"
|
120
|
-
end
|
121
|
-
|
122
|
-
params
|
123
|
-
end
|
124
|
-
|
125
|
-
def wrap_parameters(params)
|
126
|
-
@parameters.each do |key, conf|
|
127
|
-
next if conf[:wrap].nil?
|
128
|
-
|
129
|
-
if conf[:default].nil?
|
130
|
-
next if params[key].nil? || params[key].empty?
|
131
|
-
end
|
132
|
-
|
133
|
-
params[key] = conf[:wrap] % params[key]
|
134
|
-
end
|
38
|
+
param_parser = PARAM_PARSER.new
|
39
|
+
params = param_parser.parse!(self, argv)
|
135
40
|
|
136
|
-
params
|
41
|
+
(script % params).strip
|
137
42
|
end
|
138
43
|
end
|
139
44
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module DevCommands
|
5
|
+
# Command Parameter Parser
|
6
|
+
class ParamParser
|
7
|
+
def parse!(command, argv)
|
8
|
+
return {} if command.flags.empty? && command.parameters.empty?
|
9
|
+
|
10
|
+
params = parse_argv(command, argv)
|
11
|
+
params = unalias_parameters(command, params)
|
12
|
+
params = validate_parameters(command, params)
|
13
|
+
params = escape_parameters(command, params)
|
14
|
+
params = wrap_parameters(command, params)
|
15
|
+
params
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def escape_parameters(command, params)
|
21
|
+
command.parameters.each do |key, conf|
|
22
|
+
next if conf[:escape].nil?
|
23
|
+
|
24
|
+
conf[:escape].each do |char, with|
|
25
|
+
char = char.to_s unless char.is_a?(String)
|
26
|
+
params[key] = params[key].sub(char, "#{with}#{char}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
params
|
31
|
+
end
|
32
|
+
|
33
|
+
def parameters_with_defaults(command)
|
34
|
+
params = {}
|
35
|
+
|
36
|
+
command.parameters.each do |key, conf|
|
37
|
+
params[key] = '' if conf[:optional]
|
38
|
+
params[key] = conf[:default] unless conf[:default].nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
params
|
42
|
+
end
|
43
|
+
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
45
|
+
def parse_argv(command, argv)
|
46
|
+
params = parameters_with_defaults(command)
|
47
|
+
|
48
|
+
begin
|
49
|
+
OptionParser.new do |opts|
|
50
|
+
command.flags.each do |key, conf|
|
51
|
+
params[key] = ''
|
52
|
+
|
53
|
+
opts.on("--#{key}", "Flag: #{key}") do
|
54
|
+
params[key] = conf[:value] || "--#{key}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
command.parameters.each_key do |key|
|
59
|
+
opts.on("--#{key} OPTION", "Parameter: #{key}") do |o|
|
60
|
+
params[key] = o
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end.parse!(argv)
|
64
|
+
rescue OptionParser::InvalidOption => e
|
65
|
+
e.recover(argv)
|
66
|
+
end
|
67
|
+
|
68
|
+
params = passthru_parameters(params, command, argv) unless argv.empty?
|
69
|
+
params
|
70
|
+
end
|
71
|
+
# rubocop:enable Metrics/MethodLength
|
72
|
+
|
73
|
+
def passthru_parameters(params, command, argv)
|
74
|
+
has_passthru = false
|
75
|
+
|
76
|
+
command.parameters.each do |key, conf|
|
77
|
+
next unless conf[:passthru]
|
78
|
+
|
79
|
+
params[key] = argv.join(' ')
|
80
|
+
has_passthru = true
|
81
|
+
end
|
82
|
+
|
83
|
+
raise OptionParser::InvalidOption, argv unless has_passthru
|
84
|
+
|
85
|
+
params
|
86
|
+
end
|
87
|
+
|
88
|
+
def unalias_parameters(command, params)
|
89
|
+
command.parameters.each do |key, conf|
|
90
|
+
next if params[key].nil?
|
91
|
+
next if conf[:aliases].nil?
|
92
|
+
|
93
|
+
conf[:aliases].each do |input, output|
|
94
|
+
params[key] = params[key] == input ? output : params[key]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
params
|
99
|
+
end
|
100
|
+
|
101
|
+
def validate_parameters(command, params)
|
102
|
+
command.parameters.each do |key, conf|
|
103
|
+
next if params[key].nil?
|
104
|
+
next if params[key] == '' && conf[:optional]
|
105
|
+
|
106
|
+
next if conf[:allowed].nil?
|
107
|
+
next if conf[:allowed].include?(params[key])
|
108
|
+
|
109
|
+
raise ArgumentError, "--#{key}=#{params[key]}"
|
110
|
+
end
|
111
|
+
|
112
|
+
params
|
113
|
+
end
|
114
|
+
|
115
|
+
def wrap_parameters(command, params)
|
116
|
+
command.parameters.each do |key, conf|
|
117
|
+
next if conf[:wrap].nil?
|
118
|
+
|
119
|
+
if conf[:default].nil?
|
120
|
+
next if params[key].nil? || params[key].empty?
|
121
|
+
end
|
122
|
+
|
123
|
+
params[key] = conf[:wrap] % params[key]
|
124
|
+
end
|
125
|
+
|
126
|
+
params
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-devcommands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Neudert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.58'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.58'
|
69
69
|
description: Vagrant plugin to run commands specified in a Commandfile inside one
|
70
70
|
of your vagrant boxes
|
71
71
|
email:
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/vagrant/devcommands/model/chain.rb
|
94
94
|
- lib/vagrant/devcommands/model/command.rb
|
95
95
|
- lib/vagrant/devcommands/model/command_alias.rb
|
96
|
+
- lib/vagrant/devcommands/param_parser.rb
|
96
97
|
- lib/vagrant/devcommands/plugin.rb
|
97
98
|
- lib/vagrant/devcommands/registry.rb
|
98
99
|
- lib/vagrant/devcommands/registry/messager.rb
|