vagrant-devcommands 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dd051c66c3c698629e9eeac65aab7f359e7ee230
4
- data.tar.gz: e607628cc652b04882a226f7b10def7b32152298
2
+ SHA256:
3
+ metadata.gz: '08d7a51ae5cc5cc9d25df475e2724c86d040db68249141512a4b6b6a618919cd'
4
+ data.tar.gz: 362279f7c92feb9f9ecf0b90de497a99df5fb41f362713e28b92b1b94d167752
5
5
  SHA512:
6
- metadata.gz: 25c8ef756decf39dbce7050799b841e4c4e2aefb4091fd13e12ee221e593efd0434e05e6bfb70b54fc096d473907afe2045d4427960b1878f7f19f2b75fcc1bb
7
- data.tar.gz: 8cfa604c43f53e037666378517df766b54ba936b9c428ae89e90fa950d3f2729fc66827c2911ed56e9d494e32234587dc09e935d771afff33d01772b4cc74faa
6
+ metadata.gz: 43e5dd302ca02025014a022557176f2e590b7bd96b1f3a8c5db708320c5ec56960cfc7039b1f5b806b60185e93e6940b51ca7ce4009c150944e1a55f0f27e9aa
7
+ data.tar.gz: 37c8f76d57a861f730cddbeef9bafe5d053c3f85a07f37e3267a201ec057d72e3e82e3e7b27bf6ff5dd8526f7c85260918a095fe23816d90e4f794c88fe9f01b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.12.0 (2018-04-21)
4
+
5
+ - Enhancements
6
+ - Command parameters can define alias values to be replaced before escaping
7
+ - Commandfile entries with duplicate names will now issue a warning while
8
+ still discarding all previous definitions
9
+ - Commandfile entries with unknown options will issue a warning
10
+
11
+ - Backwards incompatible changes
12
+ - Support for the already deprecated configuration parameter `:box` has
13
+ been removed
14
+
3
15
  ## v0.11.1 (2017-10-04)
4
16
 
5
17
  - Bug fixes
data/README.md CHANGED
@@ -32,7 +32,7 @@ Add to a `Commandfile` besides your `Vagrantfile`:
32
32
  command 'basic', 'hostname'
33
33
 
34
34
  command 'with_options',
35
- machine: :my_machine,
35
+ machine: 'my_machine',
36
36
  desc: 'executes "hostname" on the machine "my_machine"',
37
37
  script: 'hostname',
38
38
  tty: true,
@@ -47,7 +47,7 @@ eoh
47
47
  ```
48
48
 
49
49
  _Note_: If you are defining literal `%` (percent sign) in your commands you
50
- have to escape them using a second `%`. For example `date "+%%Y-%%m-%%d"`.
50
+ have to escape them using a second `%`. For example `date '+%%Y-%%m-%%d'`.
51
51
 
52
52
  _Note_: Spaces in command names are not supported. Definitions with spaces will
53
53
  be ignored.
@@ -64,10 +64,10 @@ sprintf syntax:
64
64
  command 'with_param',
65
65
  parameters: {
66
66
  # mandatory parameter with a description
67
- p_mandatory: { desc: "mandatory parameter to do... stuff!" },
67
+ p_mandatory: { desc: 'mandatory parameter to do... stuff!' },
68
68
 
69
69
  # parameter with default (implies optional)
70
- p_default: { default: "always" },
70
+ p_default: { default: 'always' },
71
71
 
72
72
  # parameter with escaping rule
73
73
  p_escaped: { escape: { '*' => '\\' }},
@@ -76,7 +76,12 @@ command 'with_param',
76
76
  p_optional: { optional: true },
77
77
 
78
78
  # wrapped option value
79
- p_wrapped: { wrap: "--and %s wrapped" }
79
+ p_wrapped: { wrap: '--and %s wrapped' },
80
+
81
+ # parameters with aliased values
82
+ # the aliases are resolved prior to escaping/wrapping/allowance!
83
+ # aliases are resolved in order of definition (multiple can apply)
84
+ p_aliased: { aliases: { 'foo' => 'bar' }},
80
85
 
81
86
  # parameters with a limited set of allowed values
82
87
  # the allowed values are checked prior to escaping/wrapping!
@@ -89,17 +94,17 @@ command 'with_param',
89
94
  This allows you to execute the following command:
90
95
 
91
96
  ```shell
92
- # will execute 'echo works always'
97
+ # will execute 'echo "works always"'
93
98
  vagrant run with_param --p_mandatory works
94
99
 
95
- # will execute 'echo works always like a charm'
96
- vagrant run with_param --p_mandatory works --p_optional "like a charm"
100
+ # will execute 'echo "works always like a charm"'
101
+ vagrant run with_param --p_mandatory works --p_optional 'like a charm'
97
102
 
98
- # will execute 'echo works sometimes like a charm --and is wrapped completely'
103
+ # will execute 'echo "works sometimes like a charm --and is wrapped completely"'
99
104
  vagrant run with_param \
100
105
  --p_mandatory works \
101
106
  --p_default sometimes \
102
- --p_optional "like a charm" \
107
+ --p_optional 'like a charm' \
103
108
  --p_wrapped is
104
109
  --p_limited completely
105
110
  ```
@@ -108,7 +113,7 @@ For now a command expecting one or more parameters will fail if the user does
108
113
  not provide them. Any arguments exceeding the number used are silently
109
114
  discarded.
110
115
 
111
- Escaping rules are defined as `{ "char_to_escape": "char_to_use_as_escape" }`.
116
+ Escaping rules are defined as `{ 'char_to_escape' => 'char_to_use_as_escape' }`.
112
117
  These are applied prior to interpolation into the command. Regular ruby escaping
113
118
  rules apply.
114
119
 
@@ -120,8 +125,8 @@ for later command interpolation:
120
125
  ```ruby
121
126
  command 'with_flags',
122
127
  flags: {
123
- f_standard: { desc: "standard flag" },
124
- f_valued: { value: "--f_modified" }
128
+ f_standard: { desc: 'standard flag' },
129
+ f_valued: { value: '--f_modified' }
125
130
  },
126
131
  script: 'echo "flags: %<f_standard>s"'
127
132
  ```
@@ -139,7 +144,7 @@ vagrant run with_flags --f_standard
139
144
  vagrant run with_flags --f_valued
140
145
  ```
141
146
 
142
- By default a flag gets interpolated as "--#{flagname}". If a value is defined
147
+ By default a flag gets interpolated as `--#{flagname}`. If a value is defined
143
148
  this value will be interpolated unmodified.
144
149
 
145
150
  #### Commands defined by Lambda/Proc
@@ -154,7 +159,19 @@ command 'from_proc', script: proc { 'echo "proc works"' }
154
159
 
155
160
  These will be evaluated when running the command.
156
161
 
157
- Every rule from regular scripts (parameters, escaping "%", ...) still apply.
162
+ Every rule from regular scripts (parameters, escaping `%`, ...) still apply.
163
+
164
+ #### Commands with a TTY ("interactive")
165
+
166
+ If you have a command that expects some sort of interaction with the user you
167
+ may need to set the `tty` option for a command:
168
+
169
+ ```ruby
170
+ command 'interactive', tty: true
171
+ ```
172
+
173
+ This allows full interaction with programs like `irb` or `mysql`.
174
+
158
175
 
159
176
  ### Global Command Definitions
160
177
 
@@ -222,11 +239,11 @@ chain 'my_customized_chain',
222
239
  Running the chain will execute the following commands:
223
240
 
224
241
  ```shell
225
- > vagrant run my_customized_chain --first="initial" --second="initial"
242
+ > vagrant run my_customized_chain --first='initial' --second='initial'
226
243
 
227
- vagrant run chainecho --first="param" --second="initial"
228
- vagrant run chainecho --first="initial" --second="initial"
229
- vagrant run chainecho --first="param" --second="param"
244
+ vagrant run chainecho --first='param' --second='initial'
245
+ vagrant run chainecho --first='initial' --second='initial'
246
+ vagrant run chainecho --first='param' --second='param'
230
247
  ```
231
248
 
232
249
  By default every command will be executed using the machine defined by the
@@ -286,7 +303,7 @@ installed plugin has a version below `1.3.3.7`.
286
303
  Please be aware that returning from a global commandfile completely skips
287
304
  evaluating a local one.
288
305
 
289
- ### Experimental: Command Alias Definitions
306
+ ### Command Alias Definitions
290
307
 
291
308
  For commands you want to keep generic but often call with a specific set of
292
309
  parameter values you can define an alias:
@@ -340,9 +357,9 @@ a sigil notation like the following:
340
357
  ```ruby
341
358
  command 'long_running_task',
342
359
  script: %(cd /path/to/somewhere \
343
- && echo "starting long running task" \
360
+ && echo 'starting long running task' \
344
361
  && ./long_running_task.sh \
345
- && echo "finished long running task")
362
+ && echo 'finished long running task')
346
363
  ```
347
364
 
348
365
  Using a quote delimited command definition might otherwise result in not that
@@ -1,6 +1,6 @@
1
1
  require 'vagrant'
2
2
 
3
- I18n.load_path << File.expand_path('../../../locales/en.yml', __FILE__)
3
+ I18n.load_path << File.expand_path('../../locales/en.yml', __dir__)
4
4
  I18n.reload!
5
5
 
6
6
  require 'vagrant/devcommands/synopsis'
@@ -19,8 +19,6 @@ module VagrantPlugins
19
19
  def execute
20
20
  return 127 unless read_commandfile
21
21
 
22
- deprecated_box_config?
23
-
24
22
  command = Util.argv_command(@argv, @env)
25
23
 
26
24
  return 127 unless non_empty?(command)
@@ -47,12 +45,6 @@ module VagrantPlugins
47
45
  @registry.available?(command)
48
46
  end
49
47
 
50
- def deprecated_box_config?
51
- return unless @registry.commands.values.any?(&:deprecated_box_config)
52
-
53
- Messages.deprecated_box_config(&@env.ui.method(:warn))
54
- end
55
-
56
48
  def display_alternatives(command)
57
49
  alternatives = Util.did_you_mean(command, @registry)
58
50
  alternatives = alternatives.select { |_k, v| v > 0.8 }
@@ -18,11 +18,6 @@ module VagrantPlugins
18
18
  out.call I18n.t("#{I18N_KEY}.command_no_help")
19
19
  end
20
20
 
21
- def self.deprecated_box_config(&out)
22
- out.call I18n.t("#{I18N_KEY}.deprecated_box_config")
23
- out.call ''
24
- end
25
-
26
21
  def self.missing_commandfile(&out)
27
22
  out.call I18n.t("#{I18N_KEY}.missing_commandfile")
28
23
  end
@@ -17,9 +17,6 @@ module VagrantPlugins
17
17
  attr_reader :help
18
18
  attr_reader :usage
19
19
 
20
- attr_reader :deprecated_box_config
21
-
22
- # rubocop:disable Metrics/AbcSize
23
20
  def initialize(spec)
24
21
  @name = spec[:name]
25
22
 
@@ -28,14 +25,11 @@ module VagrantPlugins
28
25
  @script = spec[:script]
29
26
  @tty = spec[:tty] == true
30
27
 
31
- @machine = spec[:machine] || spec[:box]
28
+ @machine = spec[:machine]
32
29
  @desc = spec[:desc]
33
30
  @help = spec[:help]
34
31
  @usage = spec[:usage]
35
-
36
- @deprecated_box_config = spec.key?(:box)
37
32
  end
38
- # rubocop:enable Metrics/AbcSize
39
33
 
40
34
  def run_script(argv)
41
35
  script = @script
@@ -93,10 +87,27 @@ module VagrantPlugins
93
87
  end
94
88
  end.parse!(argv)
95
89
 
96
- wrap_parameters(escape_parameters(validate_parameters(params)))
90
+ params = unalias_parameters(params)
91
+ params = validate_parameters(params)
92
+ params = escape_parameters(params)
93
+ params = wrap_parameters(params)
94
+ params
97
95
  end
98
96
  # rubocop:enable Metrics/MethodLength
99
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
+
100
111
  def validate_parameters(params)
101
112
  @parameters.each do |key, conf|
102
113
  next if params[key].nil?
@@ -15,6 +15,12 @@ module VagrantPlugins
15
15
  @chains = {}
16
16
  @commands = {}
17
17
  @command_aliases = {}
18
+
19
+ @duplicates = {
20
+ 'chains' => [],
21
+ 'commands' => [],
22
+ 'command_aliases' => []
23
+ }
18
24
  end
19
25
 
20
26
  def available?(name)
@@ -46,12 +52,54 @@ module VagrantPlugins
46
52
 
47
53
  private
48
54
 
55
+ def check_model(model, entry)
56
+ speccheck_model(model, entry)
57
+ dupcheck_model(model)
58
+ end
59
+
60
+ def dupcheck_model(model)
61
+ type = model_attr(model)
62
+ type_attr = "@#{type}"
63
+ type_entries = instance_variable_get(type_attr)
64
+
65
+ return unless type_entries[model.name]
66
+ return if @duplicates[type].include?(model.name)
67
+
68
+ @messager.def_duplicate(what: model_name(model), name: model.name)
69
+ @duplicates[type] << model.name
70
+ end
71
+
72
+ def model_attr(model)
73
+ case model
74
+ when Model::Chain
75
+ 'chains'
76
+ when Model::Command
77
+ 'commands'
78
+ when Model::CommandAlias
79
+ 'command_aliases'
80
+ end
81
+ end
82
+
83
+ def model_name(model)
84
+ case model
85
+ when Model::Chain
86
+ 'chain'
87
+ when Model::Command
88
+ 'command'
89
+ when Model::CommandAlias
90
+ 'command alias'
91
+ end
92
+ end
93
+
49
94
  def register(commandfile_entries)
50
95
  modeler = Commandfile::Modeler.new
51
96
 
52
97
  commandfile_entries.each do |entry|
53
98
  begin
54
- register_model(modeler.model(entry))
99
+ model = modeler.model(entry)
100
+
101
+ check_model(model, entry)
102
+ register_model(model)
55
103
  rescue ArgumentError => e
56
104
  @messager.def_ignored(e.message, name: entry[:name])
57
105
  end
@@ -59,9 +107,24 @@ module VagrantPlugins
59
107
  end
60
108
 
61
109
  def register_model(model)
62
- @chains[model.name] = model if model.is_a?(Model::Chain)
63
- @commands[model.name] = model if model.is_a?(Model::Command)
64
- @command_aliases[model.name] = model if model.is_a?(Model::CommandAlias)
110
+ type = model_attr(model)
111
+ type_attr = "@#{type}"
112
+ type_entries = instance_variable_get(type_attr)
113
+
114
+ type_entries[model.name] = model
115
+
116
+ instance_variable_set(type_attr, type_entries)
117
+ end
118
+
119
+ def speccheck_model(model, spec)
120
+ return unless spec[:options].is_a?(Hash)
121
+
122
+ model_attrs = model.instance_variables
123
+ spec_attrs = spec[:options].keys.map { |k| :"@#{k}" }
124
+
125
+ return if (spec_attrs - model_attrs).empty?
126
+
127
+ @messager.unknown_options(what: model_name(model), name: model.name)
65
128
  end
66
129
  end
67
130
  end
@@ -19,11 +19,21 @@ module VagrantPlugins
19
19
  @env.ui.warn I18n.t("#{I18N_KEY}.command_alias_ignored")
20
20
  end
21
21
 
22
+ def def_duplicate(args)
23
+ @env.ui.warn I18n.t("#{I18N_KEY}.def_duplicate", args)
24
+ @env.ui.warn ''
25
+ end
26
+
22
27
  def def_ignored(message, args)
23
28
  @env.ui.warn I18n.t("#{I18N_KEY}.#{message}", args)
24
29
  @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
25
30
  @env.ui.warn ''
26
31
  end
32
+
33
+ def unknown_options(args)
34
+ @env.ui.warn I18n.t("#{I18N_KEY}.unknown_options", args)
35
+ @env.ui.warn ''
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Defines the current plugin version
3
3
  module DevCommands
4
- VERSION = '0.11.1'.freeze
4
+ VERSION = '0.12.0'.freeze
5
5
  end
6
6
  end
data/locales/en.yml CHANGED
@@ -29,10 +29,6 @@ en:
29
29
  chain_no_help: No detailed help for this chain available.
30
30
  command_alias_no_help: No detailed help for this command alias available.
31
31
  command_no_help: No detailed help for this command available.
32
- deprecated_box_config: |-
33
- At least one of your commands is configured with the deprecated
34
- option ':box'. This option has been renamed to ':machine' and will
35
- stop working in a future version. Please update your Commandfile.
36
32
  missing_commandfile: Missing Commandfile
37
33
  no_commands: No commands defined!
38
34
  plugin_readme: |-
@@ -61,6 +57,8 @@ en:
61
57
  command_no_script: "The command '%<name>s' has no script defined to execute."
62
58
  command_reserved: "The command name '%<name>s' is reserved for internal usage."
63
59
  def_ignored: Your definition of it will be ignored.
60
+ def_duplicate: "The %<what>s name '%<name>s' is used more than once. Only the last definition will be available."
61
+ unknown_options: "The %<what>s '%<name>s' is defined with at least one unknown option."
64
62
 
65
63
  runner:
66
64
  invalid_parameter: "invalid parameter '%<detail>s'"
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.11.1
4
+ version: 0.12.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: 2017-10-04 00:00:00.000000000 Z
11
+ date: 2018-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.6'
47
+ version: '3.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.6'
54
+ version: '3.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.50'
61
+ version: '0.55'
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.50'
68
+ version: '0.55'
69
69
  description: Vagrant plugin to run commands specified in a Commandfile inside one
70
70
  of your vagrant boxes
71
71
  email:
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.6.13
131
+ rubygems_version: 2.7.6
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Runs vagrant commands from a Commandfile