vagrant-devcommands 0.9.0 → 0.10.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
2
  SHA1:
3
- metadata.gz: 1cdd09f90d6b080675f4b15e4fb9ec4ce3101cf2
4
- data.tar.gz: 9968d30256b15ce9247ad33c39e1e1c39a3b6daf
3
+ metadata.gz: 9050521052b96dc86341f385a13b9f7a86e9d9b7
4
+ data.tar.gz: f53326e688ccd00e6a60b6cca80996510cf5d253
5
5
  SHA512:
6
- metadata.gz: aa62d03f315aab6378feb9f9ffff8d7c3f3f22930c2b7ab177ab7afea46e34761a7cab7a5c08c4ce249cff2d6e51e288fb6a1d274663ff21b529c5d242bed272
7
- data.tar.gz: 6581d21c82f57b249c645844f4e64a5cebe36c4e5171a2992e1a9a9ba914fb4ae710b3d5ae7bfcbe56deb021e5f273910071acfdf655eedf3219d99b85419533
6
+ metadata.gz: 6153595b35c47a8f770d1a4dccdc3affe5fd816b5d8ee17c70922f13a1b19dde80ff2d38bf51f3eebee7222f728620cf3adcf09e83153100896e85465ca751fe
7
+ data.tar.gz: 3e684a23dcd43765a00283771f2106eec4b79940e534cfc5c2c534ea9355df6ab5913d7056995d8306bc6c23b8cf28122df276f29849211815ef70b223d2fc61
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.10.0 (2017-07-02)
4
+
5
+ - Enhancements
6
+ - Command alternatives provided by the "did-you-mean" feature no longer
7
+ display the full command list (help)
8
+ - Depending on the internal scoring multiple alternative commands
9
+ will be presented instead of a full command list (help)
10
+ - Minimal data for shell completion is available via the internal
11
+ `completion-data` command
12
+ - Parameters can limit the values you are allowed to pass in
13
+ - Spaces in chain/command names are now officially disallowed. Those
14
+ would have always been broken anyways, but now there is a nice message
15
+ and the commands are excluded from the various listings
16
+
17
+ - Bug fixes
18
+ - Chain names can no longer conflict with internal commands like `help`
19
+ or `version`. The respective chain definitions are dropped and a warning
20
+ is issued
21
+
3
22
  ## v0.9.0 (2017-05-20)
4
23
 
5
24
  - Enhancements
data/README.md CHANGED
@@ -35,19 +35,22 @@ command 'with_options',
35
35
  machine: :my_machine,
36
36
  desc: 'executes "hostname" on the machine "my_machine"',
37
37
  script: 'hostname',
38
- usage: 'vagrant run %{command}',
38
+ usage: 'vagrant run %<command>s',
39
39
  help: <<-eoh
40
40
  I am the help message for the command "with_options".
41
41
  I get displayed when running "vagrant run help with_options".
42
42
 
43
43
  The usage printed above the help can interpolate the name
44
- of the command name using %{command}.
44
+ of the command name using either %{command} or %<command>s.
45
45
  eoh
46
46
  ```
47
47
 
48
48
  _Note_: If you are defining literal `%` (percent sign) in your commands you
49
49
  have to escape them using a second `%`. For example `date "+%%Y-%%m-%%d"`.
50
50
 
51
+ _Note_: Spaces in command names are not supported. Definitions with spaces will
52
+ be ignored.
53
+
51
54
  #### Commands with Parameters
52
55
 
53
56
  Passing additional parameters to a command is (minimally) supported using an
@@ -70,8 +73,13 @@ command 'with_param',
70
73
 
71
74
  # wrapped option value
72
75
  p_wrapped: { wrap: "--and %s wrapped" }
76
+
77
+ # parameters with a limited set of allowed values
78
+ # the allowed values are checked prior to escaping/wrapping!
79
+ # optional parameters are only validated if given!
80
+ p_limited: { allowed: ['completely'] }
73
81
  },
74
- script: 'echo %{p_mandatory} %{p_default} %{p_escaped} %{p_optional} %{p_wrapped}'
82
+ script: 'echo %<p_mandatory>s %<p_default>s %<p_escaped>s %<p_optional>s %<p_wrapped>s %<p_limited>s'
75
83
  ```
76
84
 
77
85
  This allows you to execute the following command:
@@ -83,12 +91,13 @@ vagrant run with_param --p_mandatory works
83
91
  # will execute 'echo works always like a charm'
84
92
  vagrant run with_param --p_mandatory works --p_optional "like a charm"
85
93
 
86
- # will execute 'echo works sometimes like a charm --and is wrapped'
94
+ # will execute 'echo works sometimes like a charm --and is wrapped completely'
87
95
  vagrant run with_param \
88
96
  --p_mandatory works \
89
97
  --p_default sometimes \
90
98
  --p_optional "like a charm" \
91
99
  --p_wrapped is
100
+ --p_limited completely
92
101
  ```
93
102
 
94
103
  For now a command expecting one or more parameters will fail if the user does
@@ -110,7 +119,7 @@ command 'with_flags',
110
119
  f_standard: { desc: "standard flag" },
111
120
  f_valued: { value: "--f_modified" }
112
121
  },
113
- script: 'echo "flags: %{f_standard}"'
122
+ script: 'echo "flags: %<f_standard>s"'
114
123
  ```
115
124
 
116
125
  This definition allows the following executions:
@@ -157,7 +166,7 @@ ruby -e "require 'pathname'; puts Pathname.new(Dir.home).join('.vagrant.devcomma
157
166
 
158
167
  Any commands defined there will silently be overwritten by a local definition.
159
168
 
160
- ### Experimental: Chain Definitions
169
+ ### Chain Definitions
161
170
 
162
171
  You can define command chains to execute multiple commands in order:
163
172
 
@@ -175,7 +184,7 @@ I am the help message for the chain "my_chain".
175
184
  I get displayed when running "vagrant run help my_chain".
176
185
 
177
186
  The usage printed above the help can interpolate the name
178
- of the command name using %{command}.
187
+ of the command name using %<command>s.
179
188
  eoh
180
189
  ```
181
190
 
@@ -188,6 +197,9 @@ By default a chain breaks upon the first non-zero return value of any
188
197
  configured command. To deactivate this behaviour you can set `:break_on_error`
189
198
  to `false`. Any value other than `false` will stick to the default.
190
199
 
200
+ _Note_: Spaces in command names are not supported. Definitions with spaces will
201
+ be ignored.
202
+
191
203
  #### Chain Definitions with Pre-Defined Parameters
192
204
 
193
205
  If required you can modify the arguments given to each chain element by setting
@@ -196,7 +208,7 @@ additional/custom argv values for a single chain element:
196
208
  ```ruby
197
209
  command 'chainecho',
198
210
  parameters: { first: {}, second: {} },
199
- script: 'echo %{first} %{second}'
211
+ script: 'echo %<first>s %<second>s'
200
212
 
201
213
  chain 'my_customized_chain',
202
214
  commands: [
@@ -234,6 +246,7 @@ chain 'customized_chain_machine',
234
246
  { command: 'chainecho', machine: 'secondary' },
235
247
  { command: 'chainecho', machine: 'tertiary' }
236
248
  ]
249
+ ```
237
250
 
238
251
  Running the chain will execute the following commands:
239
252
 
@@ -272,6 +285,18 @@ installed plugin has a version below `1.3.3.7`.
272
285
  Please be aware that returning from a global commandfile completely skips
273
286
  evaluating a local one.
274
287
 
288
+ ### Experimental: Shell Completion
289
+
290
+ Completion data for your shell is available via internal command:
291
+
292
+ ```shell
293
+ # list commands
294
+ vagrant run completion-data
295
+
296
+ # list command flags/parameters
297
+ vagrant run completion-data my-command
298
+ ```
299
+
275
300
 
276
301
  ## Notes for Windows Users
277
302
 
@@ -2,10 +2,6 @@ module VagrantPlugins
2
2
  module DevCommands
3
3
  # Defines the executable vagrant command
4
4
  class Command < Vagrant.plugin(2, :command)
5
- NAMESPACE_RUNNER = VagrantPlugins::DevCommands::Runner
6
- MESSAGES = VagrantPlugins::DevCommands::Messages
7
- UTIL = VagrantPlugins::DevCommands::Util
8
-
9
5
  def self.synopsis
10
6
  synopsis = VagrantPlugins::DevCommands::SYNOPSIS
11
7
 
@@ -43,8 +39,7 @@ module VagrantPlugins
43
39
  def available?(command)
44
40
  unless @registry.available?(command)
45
41
  display_error("Invalid command \"#{command}\"!")
46
- did_you_mean(command)
47
- run_internal('help', ['--commands'])
42
+ display_alternatives(command)
48
43
  end
49
44
 
50
45
  @registry.available?(command)
@@ -53,13 +48,22 @@ module VagrantPlugins
53
48
  def deprecated_box_config?
54
49
  return unless @registry.commands.values.any?(&:deprecated_box_config)
55
50
 
56
- MESSAGES.deprecated_box_config(&@env.ui.method(:warn))
51
+ Messages.deprecated_box_config(&@env.ui.method(:warn))
57
52
  end
58
53
 
59
- def did_you_mean(command)
60
- alternative, score = Util.did_you_mean(command, @registry)
54
+ def display_alternatives(command)
55
+ alternatives = Util.did_you_mean(command, @registry)
56
+ alternatives = alternatives.select { |_k, v| v > 0.8 }
57
+
58
+ return false if alternatives.empty?
59
+
60
+ if alternatives.length == 1
61
+ display_error('Did you mean this?', true)
62
+ else
63
+ display_error('Did you mean one of these?', true)
64
+ end
61
65
 
62
- display_error("Did you mean #{alternative}?", true) if 0.8 < score
66
+ alternatives.sort.each { |k, _v| display_error(" #{k}") }
63
67
  end
64
68
 
65
69
  def display_error(msg, pre_ln = false, post_ln = false)
@@ -81,8 +85,8 @@ module VagrantPlugins
81
85
  commandfile = Commandfile.new(@env)
82
86
 
83
87
  unless commandfile.exist?
84
- MESSAGES.missing_commandfile(&@env.ui.method(:error))
85
- MESSAGES.pre_ln(:plugin_readme, &@env.ui.method(:info))
88
+ Messages.missing_commandfile(&@env.ui.method(:error))
89
+ Messages.pre_ln(:plugin_readme, &@env.ui.method(:info))
86
90
 
87
91
  return false
88
92
  end
@@ -105,7 +109,7 @@ module VagrantPlugins
105
109
  end
106
110
 
107
111
  def run_internal(command, args = nil)
108
- runner = NAMESPACE_RUNNER::InternalCommand.new(
112
+ runner = Runner::InternalCommand.new(
109
113
  self, @argv, @env, @registry
110
114
  )
111
115
 
@@ -122,9 +126,9 @@ module VagrantPlugins
122
126
 
123
127
  def runner_for(command)
124
128
  if @registry.valid_command?(command)
125
- NAMESPACE_RUNNER::Command.new(self, @argv, @env, @registry)
129
+ Runner::Command.new(self, @argv, @env, @registry)
126
130
  else
127
- NAMESPACE_RUNNER::Chain.new(self, @argv, @env, @registry)
131
+ Runner::Chain.new(self, @argv, @env, @registry)
128
132
  end
129
133
  end
130
134
  end
@@ -9,7 +9,7 @@ module VagrantPlugins
9
9
  end
10
10
 
11
11
  def exist?
12
- nil != path
12
+ path != nil
13
13
  end
14
14
 
15
15
  def path
@@ -20,7 +20,7 @@ module VagrantPlugins
20
20
  private
21
21
 
22
22
  def arguments(arguments, title)
23
- return if arguments.nil?
23
+ return if arguments.nil? || arguments.empty?
24
24
 
25
25
  info("#{title}:", true)
26
26
  arguments_body(arguments)
@@ -67,9 +67,9 @@ module VagrantPlugins
67
67
  def usage_params(usage, command)
68
68
  [
69
69
  usage,
70
- UTIL.collect_mandatory_params(command.parameters || {}),
71
- UTIL.collect_optional_params(command.parameters || {}),
72
- UTIL.collect_flags(command.flags || {})
70
+ UTIL.collect_mandatory_params(command.parameters),
71
+ UTIL.collect_optional_params(command.parameters),
72
+ UTIL.collect_flags(command.flags)
73
73
  ].flatten.compact.join(' ').strip
74
74
  end
75
75
  end
@@ -0,0 +1,52 @@
1
+ module VagrantPlugins
2
+ module DevCommands
3
+ module InternalCommand
4
+ # Internal "completion-data" command
5
+ class CompletionData
6
+ def initialize(env, registry)
7
+ @env = env
8
+ @registry = registry
9
+ end
10
+
11
+ def execute(argv)
12
+ return if @registry.commands.empty?
13
+
14
+ command = VagrantPlugins::DevCommands::Util.argv_command(argv, @env)
15
+ compdata =
16
+ if command.nil?
17
+ command_completion
18
+ else
19
+ argument_completion(command)
20
+ end
21
+
22
+ @env.ui.info(compdata, new_line: false)
23
+ end
24
+
25
+ private
26
+
27
+ def argument_completion(command)
28
+ spec = registry_spec(command)
29
+
30
+ return '' if spec.nil?
31
+
32
+ (spec.flags.keys + spec.parameters.keys).sort.join(' ')
33
+ end
34
+
35
+ def command_completion
36
+ (
37
+ @registry.chains.keys +
38
+ @registry.commands.keys +
39
+ VagrantPlugins::DevCommands::Registry::RESERVED_COMMANDS
40
+ ).sort.join(' ')
41
+ end
42
+
43
+ def registry_spec(name)
44
+ return nil if @registry.reserved_command?(name)
45
+ return @registry.commands[name] if @registry.valid_command?(name)
46
+
47
+ nil
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -46,7 +46,7 @@ module VagrantPlugins
46
46
  internal_help_header(command)
47
47
  info(internal_commands[command].help.strip, true)
48
48
 
49
- message(:plugin_readme, true) if 'help' == command
49
+ message(:plugin_readme, true) if command == 'help'
50
50
  end
51
51
 
52
52
  def internal_help_header(command)
@@ -65,7 +65,7 @@ module VagrantPlugins
65
65
  end
66
66
 
67
67
  def plugin_help(command)
68
- message(:plugin_usage) unless '--commands' == command
68
+ message(:plugin_usage) unless command == '--commands'
69
69
 
70
70
  pad_to = UTIL.max_pad([internal_commands,
71
71
  @registry.commands,
@@ -4,17 +4,24 @@ module VagrantPlugins
4
4
  class InternalSpec
5
5
  I18N_KEY = 'vagrant_devcommands.internal'.freeze
6
6
 
7
+ COMPLETION_DATA = {
8
+ desc: I18n.t("#{I18N_KEY}.completion-data.desc"),
9
+ name: 'completion-data',
10
+ usage: 'vagrant run %<command>s',
11
+ help: I18n.t("#{I18N_KEY}.completion-data.help")
12
+ }.freeze
13
+
7
14
  HELP = {
8
15
  desc: I18n.t("#{I18N_KEY}.help.desc"),
9
16
  name: 'help',
10
- usage: 'vagrant run %{command} [command]',
17
+ usage: 'vagrant run %<command>s [command]',
11
18
  help: I18n.t("#{I18N_KEY}.help.help")
12
19
  }.freeze
13
20
 
14
21
  VERSION = {
15
22
  desc: I18n.t("#{I18N_KEY}.version.desc"),
16
23
  name: 'version',
17
- usage: 'vagrant run %{command}',
24
+ usage: 'vagrant run %<command>s',
18
25
  help: I18n.t("#{I18N_KEY}.version.help")
19
26
  }.freeze
20
27
  end
@@ -16,7 +16,7 @@ module VagrantPlugins
16
16
  @desc = spec[:desc]
17
17
  @help = spec[:help]
18
18
 
19
- @break_on_error = false != spec[:break_on_error]
19
+ @break_on_error = spec[:break_on_error] != false
20
20
  end
21
21
 
22
22
  def break_on_error?
@@ -21,8 +21,8 @@ module VagrantPlugins
21
21
  def initialize(spec)
22
22
  @name = spec[:name]
23
23
 
24
- @flags = spec[:flags]
25
- @parameters = spec[:parameters]
24
+ @flags = spec[:flags] || {}
25
+ @parameters = spec[:parameters] || {}
26
26
  @script = spec[:script]
27
27
 
28
28
  @machine = spec[:machine] || spec[:box]
@@ -38,73 +38,87 @@ module VagrantPlugins
38
38
  script = script.call if script.is_a?(Proc)
39
39
 
40
40
  opts = {}
41
- opts = parse_argv(argv) if @flags || @parameters
41
+ opts = parse_argv(argv) unless @flags.empty? && @parameters.empty?
42
42
 
43
43
  (script % opts).strip
44
44
  end
45
45
 
46
46
  private
47
47
 
48
- def escape_option_values(options)
49
- (@parameters || {}).each do |key, conf|
48
+ def escape_parameters(params)
49
+ @parameters.each do |key, conf|
50
50
  next if conf[:escape].nil?
51
51
 
52
52
  conf[:escape].each do |char, with|
53
- char = char.to_s unless char.is_a?(String)
54
- options[key] = options[key].sub(char, "#{with}#{char}")
53
+ char = char.to_s unless char.is_a?(String)
54
+ params[key] = params[key].sub(char, "#{with}#{char}")
55
55
  end
56
56
  end
57
57
 
58
- options
58
+ params
59
59
  end
60
60
 
61
- def options_with_defaults
62
- options = {}
61
+ def parameters_with_defaults
62
+ params = {}
63
63
 
64
- (@parameters || {}).each do |key, conf|
65
- options[key] = '' if conf[:optional]
66
- options[key] = conf[:default] unless conf[:default].nil?
64
+ @parameters.each do |key, conf|
65
+ params[key] = '' if conf[:optional]
66
+ params[key] = conf[:default] unless conf[:default].nil?
67
67
  end
68
68
 
69
- options
69
+ params
70
70
  end
71
71
 
72
72
  # rubocop:disable Metrics/MethodLength
73
73
  def parse_argv(argv)
74
- options = options_with_defaults
74
+ params = parameters_with_defaults
75
75
 
76
76
  OptionParser.new do |opts|
77
- (@flags || {}).each do |key, conf|
78
- options[key] = ''
77
+ @flags.each do |key, conf|
78
+ params[key] = ''
79
79
 
80
80
  opts.on("--#{key}", "Flag: #{key}") do
81
- options[key] = conf[:value] || "--#{key}"
81
+ params[key] = conf[:value] || "--#{key}"
82
82
  end
83
83
  end
84
84
 
85
- (@parameters || {}).each do |key, _conf|
85
+ @parameters.each do |key, _conf|
86
86
  opts.on("--#{key} OPTION", "Parameter: #{key}") do |o|
87
- options[key] = o
87
+ params[key] = o
88
88
  end
89
89
  end
90
90
  end.parse!(argv)
91
91
 
92
- wrap_option_values(escape_option_values(options))
92
+ wrap_parameters(escape_parameters(validate_parameters(params)))
93
93
  end
94
94
  # rubocop:enable Metrics/MethodLength
95
95
 
96
- def wrap_option_values(options)
97
- (@parameters || {}).each do |key, conf|
96
+ def validate_parameters(params)
97
+ @parameters.each do |key, conf|
98
+ next if params[key].nil?
99
+ next if params[key] == '' && conf[:optional]
100
+
101
+ next if conf[:allowed].nil?
102
+ next if conf[:allowed].include?(params[key])
103
+
104
+ raise ArgumentError, "--#{key}=#{params[key]}"
105
+ end
106
+
107
+ params
108
+ end
109
+
110
+ def wrap_parameters(params)
111
+ @parameters.each do |key, conf|
98
112
  next if conf[:wrap].nil?
99
113
 
100
114
  if conf[:default].nil?
101
- next if options[key].nil? || options[key].empty?
115
+ next if params[key].nil? || params[key].empty?
102
116
  end
103
117
 
104
- options[key] = conf[:wrap] % options[key]
118
+ params[key] = conf[:wrap] % params[key]
105
119
  end
106
120
 
107
- options
121
+ params
108
122
  end
109
123
  end
110
124
  end
@@ -2,10 +2,8 @@ module VagrantPlugins
2
2
  module DevCommands
3
3
  # Vagrant command registry
4
4
  class Registry
5
- I18N_KEY = 'vagrant_devcommands.registry'.freeze
6
- NAMESPACE_MODEL = VagrantPlugins::DevCommands::Model
7
-
8
- RESERVED_COMMANDS = %w[help version].freeze
5
+ I18N_KEY = 'vagrant_devcommands.registry'.freeze
6
+ RESERVED_COMMANDS = %w[completion-data help version].freeze
9
7
 
10
8
  attr_accessor :chains
11
9
  attr_accessor :commands
@@ -24,9 +22,9 @@ module VagrantPlugins
24
22
  global = commandfile.path_global
25
23
  local = commandfile.path
26
24
 
27
- contents = ''
28
- contents += "\n" + global.read unless nil == global
29
- contents += "\n" + local.read unless nil == local
25
+ contents = ''
26
+ contents += "\n" + global.read unless global.nil?
27
+ contents += "\n" + local.read unless local.nil?
30
28
 
31
29
  instance_eval(contents)
32
30
  resolve_naming_conflicts
@@ -50,63 +48,54 @@ module VagrantPlugins
50
48
  def chain(name, options = nil)
51
49
  options = {} unless options.is_a?(Hash)
52
50
  options[:commands] = {} unless options.key?(:commands)
51
+ options[:name] = name
53
52
 
54
- return empty_chain_warning(name) if options[:commands].empty?
53
+ if options[:commands].empty?
54
+ return warn_def_ignored('chain_empty', name: name)
55
+ end
55
56
 
56
- options[:name] = name
57
+ if name.include?(' ')
58
+ return warn_def_ignored('chain_name_space', name: name)
59
+ end
57
60
 
58
- @chains[name] = NAMESPACE_MODEL::Chain.new(options)
61
+ @chains[name] = Model::Chain.new(options)
59
62
  end
60
63
 
64
+ # rubocop:disable Metrics/MethodLength
61
65
  def command(name, options = nil)
62
- return reserved_warning(name) if reserved_command?(name)
63
-
64
- options = { script: options } unless options.is_a?(Hash)
66
+ if reserved_command?(name)
67
+ return warn_def_ignored('command_reserved', name: name)
68
+ end
65
69
 
66
- return script_warning(name) unless valid_script?(options[:script])
70
+ if name.include?(' ')
71
+ return warn_def_ignored('command_name_space', name: name)
72
+ end
67
73
 
74
+ options = { script: options } unless options.is_a?(Hash)
68
75
  options[:name] = name
69
76
 
70
- @commands[name] = NAMESPACE_MODEL::Command.new(options)
71
- end
72
-
73
- def empty_chain_warning(name)
74
- @env.ui.warn I18n.t("#{I18N_KEY}.empty_chain", name: name)
75
- @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
76
- @env.ui.warn ''
77
- end
78
-
79
- def missing_chain_command_warning(chain, command)
80
- i18n_args = { chain: chain, command: command }
81
-
82
- @env.ui.warn I18n.t("#{I18N_KEY}.missing_command", i18n_args)
83
- @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
84
- @env.ui.warn ''
85
- end
77
+ unless valid_script?(options[:script])
78
+ return warn_def_ignored('command_no_script', name: name)
79
+ end
86
80
 
87
- def reserved_warning(name)
88
- @env.ui.warn I18n.t("#{I18N_KEY}.reserved", name: name)
89
- @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
90
- @env.ui.warn ''
81
+ @commands[name] = Model::Command.new(options)
91
82
  end
83
+ # rubocop:enable Metrics/MethodLength
92
84
 
93
85
  def resolve_naming_conflicts
94
86
  @chains.keys.each do |chain|
95
- next unless @commands.key?(chain)
87
+ next unless valid_command?(chain)
88
+
89
+ i18n_msg = 'conflict_command'
90
+ i18n_msg = 'conflict_internal' if reserved_command?(chain)
96
91
 
97
- @env.ui.warn I18n.t("#{I18N_KEY}.conflict", name: chain)
92
+ @env.ui.warn I18n.t("#{I18N_KEY}.#{i18n_msg}", name: chain)
98
93
  @env.ui.warn I18n.t("#{I18N_KEY}.chain_ignored")
99
94
 
100
95
  @chains.delete(chain)
101
96
  end
102
97
  end
103
98
 
104
- def script_warning(name)
105
- @env.ui.warn I18n.t("#{I18N_KEY}.no_script", name: name)
106
- @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
107
- @env.ui.warn ''
108
- end
109
-
110
99
  def valid_script?(script)
111
100
  return true if script.is_a?(Proc)
112
101
 
@@ -122,7 +111,8 @@ module VagrantPlugins
122
111
  next unless element.is_a?(Hash)
123
112
  next if valid_command?(element[:command])
124
113
 
125
- missing_chain_command_warning(chain, element)
114
+ warn_def_ignored('chain_missing_command',
115
+ chain: chain, command: element)
126
116
 
127
117
  @chains.delete(chain)
128
118
 
@@ -130,6 +120,12 @@ module VagrantPlugins
130
120
  end
131
121
  end
132
122
  end
123
+
124
+ def warn_def_ignored(message, args)
125
+ @env.ui.warn I18n.t("#{I18N_KEY}.#{message}", args)
126
+ @env.ui.warn I18n.t("#{I18N_KEY}.def_ignored")
127
+ @env.ui.warn ''
128
+ end
133
129
  end
134
130
  end
135
131
  end
@@ -49,8 +49,10 @@ module VagrantPlugins
49
49
 
50
50
  def run_script(command, argv)
51
51
  command.run_script(argv)
52
+ rescue ArgumentError => e
53
+ script_error(command.name, 'parameter_not_allowed', e.message)
52
54
  rescue KeyError => e
53
- param = e.message.match(/{(.+)}/).captures.first
55
+ param = e.message.match(/key[<{](.+)[}>]/).captures.first
54
56
 
55
57
  script_error(command.name, 'missing_parameter', param)
56
58
  rescue OptionParser::InvalidOption => e
@@ -9,8 +9,15 @@ module VagrantPlugins
9
9
  UTIL = VagrantPlugins::DevCommands::Util
10
10
 
11
11
  COMMANDS = {
12
- 'help' => NAMESPACE_MODEL::Command.new(NAMESPACE_SPEC::HELP),
13
- 'version' => NAMESPACE_MODEL::Command.new(NAMESPACE_SPEC::VERSION)
12
+ 'completion-data' => NAMESPACE_MODEL::Command.new(
13
+ NAMESPACE_SPEC::COMPLETION_DATA
14
+ ),
15
+ 'help' => NAMESPACE_MODEL::Command.new(
16
+ NAMESPACE_SPEC::HELP
17
+ ),
18
+ 'version' => NAMESPACE_MODEL::Command.new(
19
+ NAMESPACE_SPEC::VERSION
20
+ )
14
21
  }.freeze
15
22
 
16
23
  def initialize(plugin, argv, env, registry)
@@ -19,10 +26,7 @@ module VagrantPlugins
19
26
  @env = env
20
27
  @registry = registry
21
28
 
22
- @internal = {
23
- 'help' => NAMESPACE_CMD::Help.new(env, registry),
24
- 'version' => NAMESPACE_CMD::Version.new(env)
25
- }
29
+ @internal = internal_commands
26
30
  end
27
31
 
28
32
  def run(command, args = nil)
@@ -33,6 +37,17 @@ module VagrantPlugins
33
37
 
34
38
  private
35
39
 
40
+ def internal_commands
41
+ {
42
+ 'completion-data' => NAMESPACE_CMD::CompletionData.new(
43
+ @env, @registry
44
+ ),
45
+
46
+ 'help' => NAMESPACE_CMD::Help.new(@env, @registry),
47
+ 'version' => NAMESPACE_CMD::Version.new(@env)
48
+ }
49
+ end
50
+
36
51
  def run_argv
37
52
  argv = @argv.dup
38
53
 
@@ -2,15 +2,14 @@ module VagrantPlugins
2
2
  module DevCommands
3
3
  # Utility module
4
4
  class Util
5
- JARO_WINKLER = VagrantPlugins::DevCommands::Util::JaroWinkler
6
-
7
5
  def self.argv_command(argv, env)
8
6
  return nil if argv.empty?
9
7
 
10
- command = argv[0].to_s
11
- command = argv[1].to_s if machine_name?(command, env.machine_index)
12
-
13
- command
8
+ if machine_name?(argv[0].to_s, env.machine_index) && argv.length > 1
9
+ argv[1].to_s
10
+ else
11
+ argv[0].to_s
12
+ end
14
13
  end
15
14
 
16
15
  def self.collect_flags(flags)
@@ -32,15 +31,17 @@ module VagrantPlugins
32
31
  end
33
32
 
34
33
  def self.did_you_mean(command, registry)
35
- alternatives = registry.commands.keys + registry.chains.keys
34
+ alternatives = registry.commands.keys +
35
+ registry.chains.keys +
36
+ Registry::RESERVED_COMMANDS
36
37
  distances = {}
37
38
 
38
39
  alternatives.each do |alternative|
39
- calculator = JARO_WINKLER.new(command, alternative)
40
+ calculator = Util::JaroWinkler.new(command, alternative)
40
41
  distances[alternative] = calculator.distance
41
42
  end
42
43
 
43
- distances.max_by { |_k, v| v }
44
+ distances
44
45
  end
45
46
 
46
47
  def self.machine_name?(name, machine_index)
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Defines the current plugin version
3
3
  module DevCommands
4
- VERSION = '0.9.0'.freeze
4
+ VERSION = '0.10.0'.freeze
5
5
  end
6
6
  end
@@ -16,6 +16,7 @@ require 'vagrant/devcommands/model/command'
16
16
 
17
17
  require 'vagrant/devcommands/help_printer/chain'
18
18
  require 'vagrant/devcommands/help_printer/command'
19
+ require 'vagrant/devcommands/internal_command/completion_data'
19
20
  require 'vagrant/devcommands/internal_command/help'
20
21
  require 'vagrant/devcommands/internal_command/version'
21
22
 
data/locales/en.yml CHANGED
@@ -1,45 +1,52 @@
1
1
  en:
2
2
  vagrant_devcommands:
3
3
  internal:
4
+ completion-data:
5
+ desc: provides shell completion data
6
+ help: Returns a list of all defined commands separated using spaces.
4
7
  help:
5
- desc: "get some plugin help"
8
+ desc: get some plugin help
6
9
  help: |-
7
10
  Display the help of the command given as the first argument if defined.
8
11
  Just like this help for the help command!
9
- usage: "Usage: %{what}"
12
+ usage: "Usage: %<what>s"
10
13
  version:
11
- desc: "get currently installed plugin version"
12
- help: "Displays the currently installed version of the plugin you are using right now."
14
+ desc: get currently installed plugin version
15
+ help: Displays the currently installed version of the plugin you are using right now.
13
16
 
14
17
  message:
15
- chain_no_help: "No detailed help for this chain available."
16
- command_no_help: "No detailed help for this command available."
18
+ chain_no_help: No detailed help for this chain available.
19
+ command_no_help: No detailed help for this command available.
17
20
  deprecated_box_config: |-
18
21
  At least one of your commands is configured with the deprecated
19
22
  option ':box'. This option has been renamed to ':machine' and will
20
23
  stop working in a future version. Please update your Commandfile.
21
- missing_commandfile: "Missing Commandfile"
22
- no_commands: "No commands defined!"
24
+ missing_commandfile: Missing Commandfile
25
+ no_commands: No commands defined!
23
26
  plugin_readme: |-
24
27
  For detailed plugin usage information please read
25
28
  the README.md at the original source location:
26
29
  >>> https://github.com/mneudert/vagrant-devcommands
27
30
  A copy of this file should be locally available at:
28
- >>> %{readme}
31
+ >>> %<readme>s
29
32
  plugin_usage: |-
30
33
  Usage: vagrant run [machine] <command>
31
34
  Help: vagrant run help <command>
32
35
 
33
36
  registry:
34
- chain_ignored: "Your chain definition will be ignored in favor of the command"
35
- conflict: "The name '%{name}' is used for both a command and a chain."
36
- def_ignored: "Your definition of it will be ignored."
37
- empty_chain: "The chain '%{name}' has no commands associated."
38
- missing_command: "The chain '%{chain}' is using at least one unknown command ('%{command}')."
39
- no_script: "The command '%{name}' has no script defined to execute."
40
- reserved: "The command name '%{name}' is reserved for internal usage."
37
+ chain_empty: "The chain '%<name>s' has no commands associated."
38
+ chain_ignored: Your chain definition will be ignored in favor of the command.
39
+ chain_missing_command: "The chain '%<chain>s' is using at least one unknown command ('%<command>s')."
40
+ chain_name_space: "The chain '%<name>s' contains spaces in it's name."
41
+ command_name_space: "The command '%<name>s' contains spaces in it's name."
42
+ command_no_script: "The command '%<name>s' has no script defined to execute."
43
+ command_reserved: "The command name '%<name>s' is reserved for internal usage."
44
+ conflict_command: "The name '%<name>s' is used for both a command and a chain."
45
+ conflict_internal: "The name '%<name>s' is used for both an internal command and a chain."
46
+ def_ignored: Your definition of it will be ignored.
41
47
 
42
48
  runner:
43
- invalid_parameter: "invalid parameter '%{detail}'"
44
- missing_parameter: "missing parameter '%{detail}'"
45
- script_error: "Could not execute %{command}: %{error}"
49
+ invalid_parameter: "invalid parameter '%<detail>s'"
50
+ missing_parameter: "missing parameter '%<detail>s'"
51
+ parameter_not_allowed: "parameter value not allowed: '%<detail>s'"
52
+ script_error: "Could not execute '%<command>s': %<error>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.9.0
4
+ version: 0.10.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-05-20 00:00:00.000000000 Z
11
+ date: 2017-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -82,6 +82,7 @@ files:
82
82
  - lib/vagrant/devcommands/commandfile.rb
83
83
  - lib/vagrant/devcommands/help_printer/chain.rb
84
84
  - lib/vagrant/devcommands/help_printer/command.rb
85
+ - lib/vagrant/devcommands/internal_command/completion_data.rb
85
86
  - lib/vagrant/devcommands/internal_command/help.rb
86
87
  - lib/vagrant/devcommands/internal_command/version.rb
87
88
  - lib/vagrant/devcommands/internal_spec.rb
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.6.6
123
+ rubygems_version: 2.5.2
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Runs vagrant commands from a Commandfile