vagrant-devcommands 0.6.0 → 0.7.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: f8cc009b295488b6a55ff950e98e4400605af8c9
4
- data.tar.gz: a9336b3f1abfd04932d9797a4a4edc11b83b868d
3
+ metadata.gz: 9c92cad09fd102f04af3040e3652d21942787743
4
+ data.tar.gz: 6f76ac6ff0b4c852b5fa3a9e7419d22a42529c42
5
5
  SHA512:
6
- metadata.gz: 357c5626f4b7d11dec138c601c3a5830ae92cefcf1bed81f68138a3aa7021dbf821f1fe8357070a6a000828307a3e042d78faf41f06b2c502621136c94c560c8
7
- data.tar.gz: 1d2dcfcfd3ce80c70f8d86ed4bd56d7cf4c63564175cba3b3280264a7888abc45a94baa444058a6de6bc38398fa08400ac3724df4ac187c4c7ed76ca7f75a0b7
6
+ metadata.gz: dc5cdabc09ff186bfceb197b3a47bb0100222771e979bf3bf6f596c1685cf7c2216997c294fff863aae382262aa1cc7ca4215bfda35bd5a2ae1b096d9a9be462
7
+ data.tar.gz: 810924b466b73987ced9be2d413788eebd42b0fbc859d140f0df4e66dd61fcc2621e31ad209ca4a9fc67fe7d2913e27757402aab72d2c5880902167fd5154af8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.7.0 (2016-09-26)
4
+
5
+ - Enhancements
6
+ - Parameters are allowed to have a detailed description
7
+ - Parameters values can be escaped before interpolation
8
+
3
9
  ## v0.6.0 (2016-05-05)
4
10
 
5
11
  - Enhancements
@@ -16,7 +22,7 @@
16
22
  - Warnings about using internal command names or missing scripts are now
17
23
  printed using the configured ui class (allows colored output)
18
24
 
19
- ## v0.5.0 (2015-03-21)
25
+ ## v0.5.0 (2016-03-21)
20
26
 
21
27
  - Enhancements
22
28
  - Commands can define a detailed help message
data/README.md CHANGED
@@ -54,39 +54,49 @@ sprintf syntax:
54
54
  ```ruby
55
55
  command 'with_param',
56
56
  parameters: {
57
- # mandatory parameter
58
- mdtry: {},
57
+ # mandatory parameter with a description
58
+ p_mandatory: { desc: "mandatory parameter to do... stuff!" },
59
+
59
60
  # parameter with default (implies optional)
60
- dflt: { default: "always" },
61
+ p_default: { default: "always" },
62
+
63
+ # parameter with escaping rule
64
+ p_escaped: { escape: { '*' => '\\' }},
65
+
61
66
  # optional parameter
62
- optnl: { optional: true },
67
+ p_optional: { optional: true },
68
+
63
69
  # wrapped option value
64
- wrppd: { wrap: "--and %s wrapped" }
70
+ p_wrapped: { wrap: "--and %s wrapped" }
65
71
  },
66
- script: 'echo %{mdtry} %{dflt} %{optnl} %{wrppd}'
72
+ script: 'echo %{p_mandatory} %{p_default} %{p_escaped} %{p_optional} %{p_wrapped}'
67
73
  ```
68
74
 
69
75
  This allows you to execute the following command:
70
76
 
71
77
  ```shell
72
78
  # will execute 'echo works always'
73
- vagrant run with_param --mdtry works
79
+ vagrant run with_param --p_mandatory works
74
80
 
75
81
  # will execute 'echo works always like a charm'
76
- vagrant run with_param --mdtry works --optnl "like a charm"
82
+ vagrant run with_param --p_mandatory works --p_optional "like a charm"
77
83
 
78
84
  # will execute 'echo works sometimes like a charm --and is wrapped'
79
85
  vagrant run with_param \
80
- --mdtry works \
81
- --dflt sometimes \
82
- --optnl "like a charm" \
83
- --wrppd is
86
+ --p_mandatory works \
87
+ --p_default sometimes \
88
+ --p_optional "like a charm" \
89
+ --p_wrapped is
84
90
  ```
85
91
 
86
92
  For now a command expecting one or more parameters will fail if the user does
87
93
  not provide them. Any arguments exceeding the number used are silently
88
94
  discarded.
89
95
 
96
+ Escaping rules are defined as `{ "char_to_escape": "char_to_use_as_escape" }`.
97
+ These are applied prior to interpolation into the command. Regular ruby escaping
98
+ rules apply.
99
+
90
100
  #### Commands defined by Lambda/Proc
91
101
 
92
102
  You can (more or less) dynamically generate your scripts by defining the
@@ -62,7 +62,7 @@ module VagrantPlugins
62
62
  commandfile = CommandFile.new(@env)
63
63
 
64
64
  unless commandfile.exist?
65
- @env.ui.error 'Missing "Commandfile"'
65
+ @env.ui.error 'Missing Commandfile'
66
66
 
67
67
  return false
68
68
  end
@@ -36,18 +36,17 @@ module VagrantPlugins
36
36
 
37
37
  private
38
38
 
39
- def parse_argv(argv)
40
- options = options_with_defaults
39
+ def escape_option_values(options)
40
+ @parameters.each do |key, conf|
41
+ next if conf[:escape].nil?
41
42
 
42
- OptionParser.new do |opts|
43
- @parameters.each do |key, _conf|
44
- opts.on("--#{key} OPTION", "Parameter: #{key}") do |o|
45
- options[key] = o
46
- end
43
+ conf[:escape].each do |char, with|
44
+ char = char.to_s unless char.is_a?(String)
45
+ options[key] = options[key].sub(char, "#{with}#{char}")
47
46
  end
48
- end.parse!(argv)
47
+ end
49
48
 
50
- wrap_option_values options
49
+ options
51
50
  end
52
51
 
53
52
  def options_with_defaults
@@ -61,6 +60,20 @@ module VagrantPlugins
61
60
  options
62
61
  end
63
62
 
63
+ def parse_argv(argv)
64
+ options = options_with_defaults
65
+
66
+ OptionParser.new do |opts|
67
+ @parameters.each do |key, _conf|
68
+ opts.on("--#{key} OPTION", "Parameter: #{key}") do |o|
69
+ options[key] = o
70
+ end
71
+ end
72
+ end.parse!(argv)
73
+
74
+ wrap_option_values(escape_option_values(options))
75
+ end
76
+
64
77
  def wrap_option_values(options)
65
78
  @parameters.each do |key, conf|
66
79
  next if conf[:wrap].nil?
@@ -2,17 +2,18 @@ module VagrantPlugins
2
2
  module DevCommands
3
3
  # Handles internal commands and their execution.
4
4
  class Internal
5
- NAMESPACE = VagrantPlugins::DevCommands::InternalCommand
5
+ NAMESPACE_CMD = VagrantPlugins::DevCommands::InternalCommand
6
+ NAMESPACE_SPEC = VagrantPlugins::DevCommands::InternalSpec
6
7
 
7
8
  COMMANDS = {
8
- 'help' => CommandDef.new(NAMESPACE::Help::SPEC),
9
- 'version' => CommandDef.new(NAMESPACE::Version::SPEC)
9
+ 'help' => CommandDef.new(NAMESPACE_SPEC::HELP),
10
+ 'version' => CommandDef.new(NAMESPACE_SPEC::VERSION)
10
11
  }.freeze
11
12
 
12
13
  def initialize(env, registry)
13
14
  @internal = {
14
- 'help' => NAMESPACE::Help.new(env, registry),
15
- 'version' => NAMESPACE::Version.new(env)
15
+ 'help' => NAMESPACE_CMD::Help.new(env, registry),
16
+ 'version' => NAMESPACE_CMD::Version.new(env)
16
17
  }
17
18
  @registry = registry
18
19
  end
@@ -3,15 +3,8 @@ module VagrantPlugins
3
3
  module InternalCommand
4
4
  # Internal "help" command
5
5
  class Help
6
- SPEC = {
7
- desc: 'display this help message',
8
- name: 'help',
9
- usage: 'vagrant run %{command} [command]',
10
- help: <<-eoh
11
- Display the help of the command given as the first argument if defined.
12
- Just like this help for the help command!
13
- eoh
14
- }.freeze
6
+ UTIL = VagrantPlugins::DevCommands::Util
7
+ MESSAGES = VagrantPlugins::DevCommands::Messages
15
8
 
16
9
  def initialize(env, registry)
17
10
  @env = env
@@ -19,7 +12,7 @@ eoh
19
12
  end
20
13
 
21
14
  def execute(argv)
22
- return plugin_help_empty if @registry.commands.empty?
15
+ return message(:no_commands) if @registry.commands.empty?
23
16
 
24
17
  command = argv[0]
25
18
 
@@ -33,13 +26,17 @@ eoh
33
26
 
34
27
  def command_help(command)
35
28
  command_help_header(command)
29
+ command_help_parameters(command)
30
+ command_help_body(@registry.commands[command].help)
31
+ end
36
32
 
33
+ def command_help_body(help)
37
34
  @env.ui.info ''
38
35
 
39
- if @registry.commands[command].help.nil?
40
- @env.ui.info 'No detailed help for this command available.'
36
+ if help.nil?
37
+ message(:no_help)
41
38
  else
42
- @env.ui.info @registry.commands[command].help
39
+ @env.ui.info help.strip
43
40
  end
44
41
  end
45
42
 
@@ -54,12 +51,22 @@ eoh
54
51
  @env.ui.info "Usage: #{usage}"
55
52
  end
56
53
 
57
- def command_pad_to
58
- internal_commands
59
- .merge(@registry.commands)
60
- .keys
61
- .map(&:length)
62
- .max
54
+ def command_help_parameters(command)
55
+ return if @registry.commands[command].parameters.nil?
56
+
57
+ @env.ui.info ''
58
+ @env.ui.info 'Parameters:'
59
+
60
+ command_help_parameters_body(command)
61
+ end
62
+
63
+ def command_help_parameters_body(command)
64
+ params = @registry.commands[command].parameters
65
+ pad_to = UTIL.pad_to(params)
66
+
67
+ params.sort.each do |name, options|
68
+ @env.ui.info UTIL.padded_columns(pad_to, name, options[:desc])
69
+ end
63
70
  end
64
71
 
65
72
  def internal_commands
@@ -70,7 +77,7 @@ eoh
70
77
  internal_help_header(command)
71
78
 
72
79
  @env.ui.info ''
73
- @env.ui.info internal_commands[command].help
80
+ @env.ui.info internal_commands[command].help.strip
74
81
  end
75
82
 
76
83
  def internal_help_header(command)
@@ -80,13 +87,19 @@ eoh
80
87
  @env.ui.info "Usage: #{usage}"
81
88
  end
82
89
 
90
+ def message(msg)
91
+ MESSAGES.public_send(msg, &@env.ui.method(:info))
92
+ end
93
+
83
94
  def plugin_help(command)
84
- plugin_help_usage unless '--commands' == command
95
+ message(:plugin_usage) unless '--commands' == command
85
96
 
86
- pad_to = command_pad_to
97
+ pad_to = UTIL.pad_to(internal_commands.merge(@registry.commands))
87
98
 
88
99
  plugin_help_commands('Available', @registry.commands, pad_to)
89
100
  plugin_help_commands('Internal', internal_commands, pad_to)
101
+
102
+ message(:plugin_usage_info) unless '--commands' == command
90
103
  end
91
104
 
92
105
  def plugin_help_commands(type, commands, pad_to)
@@ -94,23 +107,10 @@ eoh
94
107
  @env.ui.info "#{type} commands:"
95
108
 
96
109
  commands.sort.each do |name, command|
97
- if command.desc.nil?
98
- @env.ui.info " #{name}"
99
- else
100
- @env.ui.info " #{name.ljust(pad_to)} #{command.desc}"
101
- end
110
+ @env.ui.info UTIL.padded_columns(pad_to, name, command.desc)
102
111
  end
103
112
  end
104
113
 
105
- def plugin_help_empty
106
- @env.ui.info 'No commands defined!'
107
- end
108
-
109
- def plugin_help_usage
110
- @env.ui.info 'Usage: vagrant run [box] <command>'
111
- @env.ui.info 'Help: vagrant run help <command>'
112
- end
113
-
114
114
  def usage_params(usage, command)
115
115
  return usage if command.parameters.nil?
116
116
 
@@ -3,15 +3,6 @@ module VagrantPlugins
3
3
  module InternalCommand
4
4
  # Internal "version" command
5
5
  class Version
6
- SPEC = {
7
- desc: 'display currently used the plugin version',
8
- name: 'version',
9
- usage: 'vagrant run %{command}',
10
- help: <<-eoh
11
- Displays the currently installed version the plugin you are using right now.
12
- eoh
13
- }.freeze
14
-
15
6
  def initialize(env)
16
7
  @env = env
17
8
  end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module DevCommands
3
+ # Contains the specs for internal commands
4
+ class InternalSpec
5
+ HELP = {
6
+ desc: I18n.t('vagrant_devcommands.internal.help.desc'),
7
+ name: 'help',
8
+ usage: 'vagrant run %{command} [command]',
9
+ help: I18n.t('vagrant_devcommands.internal.help.help')
10
+ }.freeze
11
+
12
+ VERSION = {
13
+ desc: I18n.t('vagrant_devcommands.internal.version.desc'),
14
+ name: 'version',
15
+ usage: 'vagrant run %{command}',
16
+ help: I18n.t('vagrant_devcommands.internal.version.help')
17
+ }.freeze
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ require 'optparse'
2
+
3
+ module VagrantPlugins
4
+ module DevCommands
5
+ # Provides access to messages used by the plugin
6
+ class Messages
7
+ def self.no_help(&out)
8
+ out.call 'No detailed help for this command available.'
9
+ end
10
+
11
+ def self.no_commands(&out)
12
+ out.call 'No commands defined!'
13
+ end
14
+
15
+ def self.plugin_usage(&out)
16
+ out.call 'Usage: vagrant run [box] <command>'
17
+ out.call 'Help: vagrant run help <command>'
18
+ end
19
+
20
+ def self.plugin_usage_info(&out)
21
+ curdir = File.expand_path(File.dirname(__FILE__))
22
+ readme = File.expand_path(File.join(curdir, '../../../README.md'))
23
+
24
+ out.call ''
25
+ out.call 'For detailed usage please read the'
26
+ out.call 'README.md at the original source location:'
27
+ out.call '>>> https://github.com/mneudert/vagrant-devcommands'
28
+ out.call 'A copy of this file should be locally available at'
29
+ out.call ">>> #{readme}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module DevCommands
3
+ # Utility module
4
+ class Util
5
+ def self.pad_to(items)
6
+ items.keys.map(&:length).max
7
+ end
8
+
9
+ def self.padded_columns(pad_to, left, right)
10
+ left = left.to_s unless left.is_a?(String)
11
+ right = right.to_s unless right.is_a?(String)
12
+
13
+ if right.nil?
14
+ " #{left}"
15
+ else
16
+ " #{left.ljust(pad_to)} #{right}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Defines the current plugin version
3
3
  module DevCommands
4
- VERSION = '0.6.0'.freeze
4
+ VERSION = '0.7.0'.freeze
5
5
  end
6
6
  end
@@ -1,5 +1,12 @@
1
1
  require 'vagrant'
2
2
 
3
+ I18n.load_path << File.expand_path('../../../locales/en.yml', __FILE__)
4
+ I18n.reload!
5
+
6
+ require 'vagrant/devcommands/internal_spec'
7
+ require 'vagrant/devcommands/messages'
8
+ require 'vagrant/devcommands/util'
9
+
3
10
  require 'vagrant/devcommands/internal_command/help'
4
11
  require 'vagrant/devcommands/internal_command/version'
5
12
 
data/locales/en.yml ADDED
@@ -0,0 +1,12 @@
1
+ en:
2
+ vagrant_devcommands:
3
+ internal:
4
+ help:
5
+ desc: "display this help message"
6
+ help: |-
7
+ Display the help of the command given as the first argument if defined.
8
+ Just like this help for the help command!
9
+
10
+ version:
11
+ desc: "display currently used the plugin version"
12
+ help: "Displays the currently installed version the plugin you are using right now."
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-devcommands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.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: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.2
20
- - - "<="
21
- - !ruby/object:Gem::Version
22
- version: 1.10.6
19
+ version: 1.12.5
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 1.5.2
30
- - - "<="
24
+ - - '='
31
25
  - !ruby/object:Gem::Version
32
- version: 1.10.6
26
+ version: 1.12.5
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: coveralls
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -104,9 +98,13 @@ files:
104
98
  - lib/vagrant/devcommands/internal.rb
105
99
  - lib/vagrant/devcommands/internal_command/help.rb
106
100
  - lib/vagrant/devcommands/internal_command/version.rb
101
+ - lib/vagrant/devcommands/internal_spec.rb
102
+ - lib/vagrant/devcommands/messages.rb
107
103
  - lib/vagrant/devcommands/plugin.rb
108
104
  - lib/vagrant/devcommands/registry.rb
105
+ - lib/vagrant/devcommands/util.rb
109
106
  - lib/vagrant/devcommands/version.rb
107
+ - locales/en.yml
110
108
  homepage: https://github.com/mneudert/vagrant-devcommands
111
109
  licenses:
112
110
  - MIT