vagrant-devcommands 0.5.0 → 0.6.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 +16 -0
- data/README.md +41 -2
- data/lib/vagrant/devcommands/command.rb +20 -9
- data/lib/vagrant/devcommands/command_def.rb +2 -1
- data/lib/vagrant/devcommands/command_file.rb +11 -1
- data/lib/vagrant/devcommands/internal.rb +3 -3
- data/lib/vagrant/devcommands/internal_command/help.rb +63 -43
- data/lib/vagrant/devcommands/internal_command/version.rb +5 -1
- data/lib/vagrant/devcommands/registry.rb +28 -10
- data/lib/vagrant/devcommands/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8cc009b295488b6a55ff950e98e4400605af8c9
|
4
|
+
data.tar.gz: a9336b3f1abfd04932d9797a4a4edc11b83b868d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357c5626f4b7d11dec138c601c3a5830ae92cefcf1bed81f68138a3aa7021dbf821f1fe8357070a6a000828307a3e042d78faf41f06b2c502621136c94c560c8
|
7
|
+
data.tar.gz: 1d2dcfcfd3ce80c70f8d86ed4bd56d7cf4c63564175cba3b3280264a7888abc45a94baa444058a6de6bc38398fa08400ac3724df4ac187c4c7ed76ca7f75a0b7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.6.0 (2016-05-05)
|
4
|
+
|
5
|
+
- Enhancements
|
6
|
+
- Command usage now displays the correct parameter syntax
|
7
|
+
- Command usage always displays mandatory parameters before optional ones
|
8
|
+
- Error output (i.e. "missing Commandfile") is now printed using
|
9
|
+
the configured ui class (allows colored output)
|
10
|
+
- Global commands can be defined using a file
|
11
|
+
named `.vagrant.devcommands` located under `Dir.home()`
|
12
|
+
- Invalid parameters are displayed in the error message
|
13
|
+
- Missing parameters are displayed in the error message
|
14
|
+
- Parameter wrapping is only done if a value is passed
|
15
|
+
or a default (at least empty string) is configured
|
16
|
+
- Warnings about using internal command names or missing scripts are now
|
17
|
+
printed using the configured ui class (allows colored output)
|
18
|
+
|
3
19
|
## v0.5.0 (2015-03-21)
|
4
20
|
|
5
21
|
- Enhancements
|
data/README.md
CHANGED
@@ -46,7 +46,7 @@ eoh
|
|
46
46
|
_Note_: If you are defining literal `%` (percent sign) in your commands you
|
47
47
|
have to escape them using a second `%`. For example `date "+%%Y-%%m-%%d"`.
|
48
48
|
|
49
|
-
####
|
49
|
+
#### Commands with Parameters
|
50
50
|
|
51
51
|
Passing additional parameters to a command is (minimally) supported using an
|
52
52
|
sprintf syntax:
|
@@ -87,7 +87,7 @@ For now a command expecting one or more parameters will fail if the user does
|
|
87
87
|
not provide them. Any arguments exceeding the number used are silently
|
88
88
|
discarded.
|
89
89
|
|
90
|
-
####
|
90
|
+
#### Commands defined by Lambda/Proc
|
91
91
|
|
92
92
|
You can (more or less) dynamically generate your scripts by defining the
|
93
93
|
command with a lambda or proc as its script.
|
@@ -102,6 +102,45 @@ These will be evaluated when running the command.
|
|
102
102
|
Every rule from regular scripts (parameters, escaping "%", ...) still apply.
|
103
103
|
|
104
104
|
|
105
|
+
### Experimental: global command definitions
|
106
|
+
|
107
|
+
To have commands available even wihout a `Commandfile` you can define the
|
108
|
+
globally. To do this just create a file named `.vagrant.devcommands` in your
|
109
|
+
`$HOME` directory.
|
110
|
+
|
111
|
+
You can use this command to find the correct path if unsure:
|
112
|
+
|
113
|
+
```shell
|
114
|
+
ruby -e "require 'pathname'; puts Pathname.new(Dir.home).join('.vagrant.devcommands')"
|
115
|
+
```
|
116
|
+
|
117
|
+
Any commands defined there will silently be overwritten by a local definition.
|
118
|
+
|
119
|
+
### Abort parsing inside Commandfile
|
120
|
+
|
121
|
+
If you, for whatever reasons, want to abort further parsing of a `Commandfile`
|
122
|
+
you can simple return from it:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
command 'foo', script: 'foo'
|
126
|
+
|
127
|
+
|
128
|
+
v_cur = Gem::Version.new(VagrantPlugins::DevCommands::VERSION)
|
129
|
+
v_min = Gem::Version.new('1.3.3.7')
|
130
|
+
|
131
|
+
return if v_cur < v_min
|
132
|
+
|
133
|
+
|
134
|
+
command 'bar', script: 'bar'
|
135
|
+
```
|
136
|
+
|
137
|
+
This example leads to the command `bar` not being available if the currently
|
138
|
+
installed plugin has a version below `1.3.3.7`.
|
139
|
+
|
140
|
+
Please be aware that returning from a global commandfile completely skips
|
141
|
+
evaluating a local one.
|
142
|
+
|
143
|
+
|
105
144
|
## Notes for Windows Users
|
106
145
|
|
107
146
|
### SSH
|
@@ -7,7 +7,7 @@ module VagrantPlugins
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(argv, env)
|
10
|
-
@registry = Registry.new
|
10
|
+
@registry = Registry.new(env)
|
11
11
|
|
12
12
|
super(argv, env)
|
13
13
|
end
|
@@ -35,7 +35,9 @@ module VagrantPlugins
|
|
35
35
|
end
|
36
36
|
|
37
37
|
unless @registry.valid_command?(command)
|
38
|
-
display_error("Invalid command \"#{command}\"
|
38
|
+
display_error("Invalid command \"#{command}\"!")
|
39
|
+
run_internal('help', ['--commands'])
|
40
|
+
|
39
41
|
return false
|
40
42
|
end
|
41
43
|
|
@@ -52,14 +54,16 @@ module VagrantPlugins
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def display_error(msg)
|
55
|
-
|
57
|
+
@env.ui.error msg
|
58
|
+
@env.ui.error ''
|
56
59
|
end
|
57
60
|
|
58
61
|
def read_commandfile
|
59
62
|
commandfile = CommandFile.new(@env)
|
60
63
|
|
61
64
|
unless commandfile.exist?
|
62
|
-
|
65
|
+
@env.ui.error 'Missing "Commandfile"'
|
66
|
+
|
63
67
|
return false
|
64
68
|
end
|
65
69
|
|
@@ -99,16 +103,23 @@ module VagrantPlugins
|
|
99
103
|
nil
|
100
104
|
end
|
101
105
|
|
102
|
-
def run_internal(command)
|
103
|
-
Internal.new(@registry).run(command, run_argv)
|
106
|
+
def run_internal(command, args = nil)
|
107
|
+
Internal.new(@env, @registry).run(command, args || run_argv)
|
104
108
|
end
|
105
109
|
|
106
110
|
def run_script(command, argv)
|
107
111
|
command.run_script(argv)
|
108
|
-
rescue KeyError
|
109
|
-
|
112
|
+
rescue KeyError => e
|
113
|
+
param = e.message.match(/{(.+)}/).captures.first
|
114
|
+
|
115
|
+
run_script_error(command.name, "missing parameter '#{param}'")
|
116
|
+
rescue OptionParser::InvalidOption => e
|
117
|
+
run_script_error(command.name, "invalid parameter '#{e.args.first}'")
|
118
|
+
end
|
110
119
|
|
111
|
-
|
120
|
+
def run_script_error(command, error)
|
121
|
+
display_error("Could not execute #{command}: #{error}!")
|
122
|
+
run_internal('help', [command])
|
112
123
|
|
113
124
|
nil
|
114
125
|
end
|
@@ -55,7 +55,7 @@ module VagrantPlugins
|
|
55
55
|
|
56
56
|
@parameters.each do |key, conf|
|
57
57
|
options[key] = '' if conf[:optional]
|
58
|
-
options[key] = conf[:default]
|
58
|
+
options[key] = conf[:default] unless conf[:default].nil?
|
59
59
|
end
|
60
60
|
|
61
61
|
options
|
@@ -64,6 +64,7 @@ module VagrantPlugins
|
|
64
64
|
def wrap_option_values(options)
|
65
65
|
@parameters.each do |key, conf|
|
66
66
|
next if conf[:wrap].nil?
|
67
|
+
next if options[key].nil? && conf[:default].nil?
|
67
68
|
|
68
69
|
options[key] = conf[:wrap] % options[key]
|
69
70
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module DevCommands
|
3
5
|
# Loads and handles the Commandfile
|
@@ -7,13 +9,21 @@ module VagrantPlugins
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def exist?
|
10
|
-
nil !=
|
12
|
+
nil != path
|
11
13
|
end
|
12
14
|
|
13
15
|
def path
|
14
16
|
find_commandfile
|
15
17
|
end
|
16
18
|
|
19
|
+
def path_global
|
20
|
+
global = Pathname.new(Dir.home).join('.vagrant.devcommands')
|
21
|
+
|
22
|
+
return global if global.file?
|
23
|
+
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
17
27
|
private
|
18
28
|
|
19
29
|
attr_accessor :env
|
@@ -9,10 +9,10 @@ module VagrantPlugins
|
|
9
9
|
'version' => CommandDef.new(NAMESPACE::Version::SPEC)
|
10
10
|
}.freeze
|
11
11
|
|
12
|
-
def initialize(registry)
|
12
|
+
def initialize(env, registry)
|
13
13
|
@internal = {
|
14
|
-
'help' => NAMESPACE::Help.new(registry),
|
15
|
-
'version' => NAMESPACE::Version.new
|
14
|
+
'help' => NAMESPACE::Help.new(env, registry),
|
15
|
+
'version' => NAMESPACE::Version.new(env)
|
16
16
|
}
|
17
17
|
@registry = registry
|
18
18
|
end
|
@@ -13,39 +13,33 @@ Just like this help for the help command!
|
|
13
13
|
eoh
|
14
14
|
}.freeze
|
15
15
|
|
16
|
-
def initialize(registry)
|
16
|
+
def initialize(env, registry)
|
17
|
+
@env = env
|
17
18
|
@registry = registry
|
18
19
|
end
|
19
20
|
|
20
21
|
def execute(argv)
|
21
|
-
if @registry.commands.empty?
|
22
|
-
|
23
|
-
|
24
|
-
end
|
22
|
+
return plugin_help_empty if @registry.commands.empty?
|
23
|
+
|
24
|
+
command = argv[0]
|
25
25
|
|
26
|
-
return plugin_help unless @registry.valid_command?(
|
27
|
-
return internal_help(
|
26
|
+
return plugin_help(command) unless @registry.valid_command?(command)
|
27
|
+
return internal_help(command) if @registry.reserved_command?(command)
|
28
28
|
|
29
|
-
command_help(
|
29
|
+
command_help(command)
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
def collect_commands
|
35
|
-
internal = VagrantPlugins::DevCommands::Internal::COMMANDS
|
36
|
-
|
37
|
-
@registry.commands.merge internal
|
38
|
-
end
|
39
|
-
|
40
34
|
def command_help(command)
|
41
35
|
command_help_header(command)
|
42
36
|
|
43
|
-
|
37
|
+
@env.ui.info ''
|
44
38
|
|
45
39
|
if @registry.commands[command].help.nil?
|
46
|
-
|
40
|
+
@env.ui.info 'No detailed help for this command available.'
|
47
41
|
else
|
48
|
-
|
42
|
+
@env.ui.info @registry.commands[command].help
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
@@ -57,60 +51,86 @@ eoh
|
|
57
51
|
usage = @registry.commands[command].usage % { command: command }
|
58
52
|
end
|
59
53
|
|
60
|
-
|
54
|
+
@env.ui.info "Usage: #{usage}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def command_pad_to
|
58
|
+
internal_commands
|
59
|
+
.merge(@registry.commands)
|
60
|
+
.keys
|
61
|
+
.map(&:length)
|
62
|
+
.max
|
63
|
+
end
|
64
|
+
|
65
|
+
def internal_commands
|
66
|
+
VagrantPlugins::DevCommands::Internal::COMMANDS
|
61
67
|
end
|
62
68
|
|
63
69
|
def internal_help(command)
|
64
70
|
internal_help_header(command)
|
65
71
|
|
66
|
-
|
67
|
-
|
72
|
+
@env.ui.info ''
|
73
|
+
@env.ui.info internal_commands[command].help
|
68
74
|
end
|
69
75
|
|
70
76
|
def internal_help_header(command)
|
71
|
-
spec =
|
77
|
+
spec = internal_commands[command]
|
72
78
|
usage = spec.usage % { command: command }
|
73
79
|
|
74
|
-
|
80
|
+
@env.ui.info "Usage: #{usage}"
|
75
81
|
end
|
76
82
|
|
77
|
-
def plugin_help
|
78
|
-
|
79
|
-
|
83
|
+
def plugin_help(command)
|
84
|
+
plugin_help_usage unless '--commands' == command
|
85
|
+
|
86
|
+
pad_to = command_pad_to
|
87
|
+
|
88
|
+
plugin_help_commands('Available', @registry.commands, pad_to)
|
89
|
+
plugin_help_commands('Internal', internal_commands, pad_to)
|
80
90
|
end
|
81
91
|
|
82
|
-
def plugin_help_commands
|
83
|
-
|
84
|
-
|
92
|
+
def plugin_help_commands(type, commands, pad_to)
|
93
|
+
@env.ui.info ''
|
94
|
+
@env.ui.info "#{type} commands:"
|
85
95
|
|
86
|
-
commands.each do |name, command|
|
96
|
+
commands.sort.each do |name, command|
|
87
97
|
if command.desc.nil?
|
88
|
-
|
98
|
+
@env.ui.info " #{name}"
|
89
99
|
else
|
90
|
-
|
100
|
+
@env.ui.info " #{name.ljust(pad_to)} #{command.desc}"
|
91
101
|
end
|
92
102
|
end
|
93
103
|
end
|
94
104
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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>'
|
100
112
|
end
|
101
113
|
|
102
114
|
def usage_params(usage, command)
|
103
115
|
return usage if command.parameters.nil?
|
104
116
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
[
|
118
|
+
usage,
|
119
|
+
usage_params_mandatory(command.parameters),
|
120
|
+
usage_params_optional(command.parameters)
|
121
|
+
].flatten.compact.join(' ').strip
|
122
|
+
end
|
123
|
+
|
124
|
+
def usage_params_mandatory(params)
|
125
|
+
params.collect do |key, opts|
|
126
|
+
"--#{key}=<#{key}>" unless opts[:optional]
|
111
127
|
end
|
128
|
+
end
|
112
129
|
|
113
|
-
|
130
|
+
def usage_params_optional(params)
|
131
|
+
params.collect do |key, opts|
|
132
|
+
"[--#{key}=<#{key}>]" if opts[:optional]
|
133
|
+
end
|
114
134
|
end
|
115
135
|
end
|
116
136
|
end
|
@@ -12,8 +12,12 @@ Displays the currently installed version the plugin you are using right now.
|
|
12
12
|
eoh
|
13
13
|
}.freeze
|
14
14
|
|
15
|
+
def initialize(env)
|
16
|
+
@env = env
|
17
|
+
end
|
18
|
+
|
15
19
|
def execute(_args)
|
16
|
-
|
20
|
+
@env.ui.info "vagrant-devcommands, version #{VERSION}"
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -6,12 +6,18 @@ module VagrantPlugins
|
|
6
6
|
|
7
7
|
attr_accessor :commands
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(env)
|
10
10
|
@commands = {}
|
11
|
+
@env = env
|
11
12
|
end
|
12
13
|
|
13
14
|
def read_commandfile(commandfile)
|
14
|
-
|
15
|
+
global = commandfile.path_global
|
16
|
+
local = commandfile.path
|
17
|
+
|
18
|
+
contents = ''
|
19
|
+
contents += "\n" + global.read unless nil == global
|
20
|
+
contents += "\n" + local.read unless nil == local
|
15
21
|
|
16
22
|
instance_eval(contents)
|
17
23
|
end
|
@@ -26,12 +32,12 @@ module VagrantPlugins
|
|
26
32
|
|
27
33
|
private
|
28
34
|
|
29
|
-
def command(name, options)
|
35
|
+
def command(name, options = nil)
|
30
36
|
return reserved_warning(name) if reserved_command?(name)
|
31
37
|
|
32
38
|
options = { script: options } unless options.is_a?(Hash)
|
33
39
|
|
34
|
-
return script_warning(name) unless
|
40
|
+
return script_warning(name) unless valid_script?(options[:script])
|
35
41
|
|
36
42
|
options[:name] = name
|
37
43
|
|
@@ -39,15 +45,27 @@ module VagrantPlugins
|
|
39
45
|
end
|
40
46
|
|
41
47
|
def script_warning(name)
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
@env.ui.warn "The command '#{name}' has no script defined to execute."
|
49
|
+
@env.ui.warn 'Your definition of it will be ignored.'
|
50
|
+
@env.ui.warn ''
|
45
51
|
end
|
46
52
|
|
47
53
|
def reserved_warning(name)
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
@env.ui.warn(
|
55
|
+
"The command name '#{name}' is reserved for internal usage."
|
56
|
+
)
|
57
|
+
|
58
|
+
@env.ui.warn 'Your definition of it will be ignored.'
|
59
|
+
@env.ui.warn ''
|
60
|
+
end
|
61
|
+
|
62
|
+
def valid_script?(script)
|
63
|
+
return true if script.is_a?(Proc)
|
64
|
+
|
65
|
+
return false unless script.is_a?(String)
|
66
|
+
return false if script.empty?
|
67
|
+
|
68
|
+
true
|
51
69
|
end
|
52
70
|
end
|
53
71
|
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.6.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-
|
11
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|