vagrant-devcommands 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +19 -0
- data/lib/vagrant/devcommands/command.rb +69 -25
- data/lib/vagrant/devcommands/internal.rb +55 -0
- data/lib/vagrant/devcommands/registry.rb +24 -19
- data/lib/vagrant/devcommands/version.rb +1 -1
- data/lib/vagrant/devcommands.rb +1 -4
- metadata +13 -9
- data/lib/vagrant/devcommands/_proxy.rb +0 -6
- data/lib/vagrant/devcommands/definer.rb +0 -24
- data/lib/vagrant/devcommands/help.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 582303dc5434a37e980ebc5345eb39a75d229d8f
|
4
|
+
data.tar.gz: 110bdb1cda070d37745cdfd2cf44d16c74a9e3c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9110c730003d6bfaf764bf50017a839b2f35708a19e1f027469deb93ed1426fd8c7f83ec7dcafe2bd8ae5ea34b8580d61945baba2a3747b90ed9c32b1d53c5
|
7
|
+
data.tar.gz: 4c8f3c651c7673f5d08173b461b63da3a02a2c0d6b0757287c367a408b6630fc6f0530f65d911d869df7870381596c3d8e8552f88331560f069d4952a1c7da39
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.4.0 (2015-12-13)
|
4
|
+
|
5
|
+
- Enhancements
|
6
|
+
- `vagrant run help` prints the plugin help (same as `vagrant run`)
|
7
|
+
- `vagrant run version` prints the currently used plugin version
|
8
|
+
- Commands can receive additional parameters from the command line
|
9
|
+
|
10
|
+
- Backwards incompatible changes
|
11
|
+
- Command names `help` and `version` are reserved for internal usage
|
12
|
+
- Depecrated command definer was removed
|
13
|
+
|
14
|
+
- Bug fixes
|
15
|
+
- Commands without a script display a message and are ignored
|
16
|
+
|
3
17
|
## v0.3.0 (2015-11-21)
|
4
18
|
|
5
19
|
- Enhancements
|
data/README.md
CHANGED
@@ -18,6 +18,25 @@ command 'with_options',
|
|
18
18
|
script: 'hostname'
|
19
19
|
```
|
20
20
|
|
21
|
+
#### Command Definition (parameters)
|
22
|
+
|
23
|
+
Passing additional parameters to a command is (minimally) supported using an
|
24
|
+
sprintf syntax:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
command 'with_param', script: 'echo "%s"'
|
28
|
+
```
|
29
|
+
|
30
|
+
This allows you to execute the following command:
|
31
|
+
|
32
|
+
```shell
|
33
|
+
# will execute something like 'echo "works"'
|
34
|
+
vagrant run with_param works
|
35
|
+
```
|
36
|
+
|
37
|
+
For now a command expecting one or more parameters will fail if the user does
|
38
|
+
not provide them. Any arguments exceeding the number used are silently
|
39
|
+
discarded.
|
21
40
|
|
22
41
|
### Command Listing
|
23
42
|
|
@@ -13,18 +13,13 @@ module VagrantPlugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute
|
16
|
-
|
17
|
-
commandfile = Commandfile.new(@env)
|
18
|
-
|
19
|
-
return display_error('Missing "Commandfile"') unless commandfile.exist?
|
16
|
+
return 127 unless read_commandfile
|
20
17
|
|
21
|
-
|
18
|
+
command = argv_command
|
22
19
|
|
23
|
-
return
|
20
|
+
return 127 unless check_command(command)
|
24
21
|
|
25
|
-
|
26
|
-
return display_error("Invalid command \"#{command}\"\n")
|
27
|
-
end
|
22
|
+
return run_internal(command) if @registry.reserved_command?(command)
|
28
23
|
|
29
24
|
run @registry.commands[command]
|
30
25
|
end
|
@@ -33,41 +28,90 @@ module VagrantPlugins
|
|
33
28
|
|
34
29
|
attr_accessor :registry
|
35
30
|
|
31
|
+
def check_command(command)
|
32
|
+
unless command
|
33
|
+
run_internal('help')
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
unless @registry.valid_command?(command)
|
38
|
+
display_error("Invalid command \"#{command}\"\n")
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def argv_command
|
46
|
+
return nil unless @argv.length
|
47
|
+
|
48
|
+
command = @argv[0]
|
49
|
+
command = @argv[1] if @env.machine_index.include?(command)
|
50
|
+
|
51
|
+
command
|
52
|
+
end
|
53
|
+
|
36
54
|
def display_error(msg)
|
37
|
-
puts(msg) &&
|
55
|
+
puts(msg) && run_internal('help')
|
38
56
|
end
|
39
57
|
|
40
|
-
def
|
41
|
-
|
58
|
+
def read_commandfile
|
59
|
+
commandfile = Commandfile.new(@env)
|
42
60
|
|
43
|
-
|
44
|
-
|
61
|
+
unless commandfile.exist?
|
62
|
+
display_error('Missing "Commandfile"')
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
|
66
|
+
@registry.read_commandfile(commandfile)
|
67
|
+
|
68
|
+
true
|
45
69
|
end
|
46
70
|
|
47
71
|
def run(command)
|
48
|
-
argv
|
72
|
+
argv = run_argv
|
73
|
+
box = run_box(command)
|
74
|
+
script = run_script(command[:script], argv)
|
49
75
|
|
50
|
-
|
76
|
+
return 2 unless script
|
77
|
+
|
78
|
+
with_target_vms(box, single_target: true) do |vm|
|
51
79
|
env = vm.action(:ssh_run,
|
52
80
|
ssh_opts: { extra_args: ['-q'] },
|
53
|
-
ssh_run_command:
|
81
|
+
ssh_run_command: script)
|
54
82
|
|
55
83
|
return env[:ssh_run_exit_status] || 0
|
56
84
|
end
|
57
85
|
end
|
58
86
|
|
59
|
-
def run_argv
|
87
|
+
def run_argv
|
60
88
|
argv = @argv.dup
|
61
|
-
argv.pop
|
62
|
-
|
63
|
-
if cmd[:box] && argv.empty?
|
64
|
-
argv.unshift(cmd[:box].to_s)
|
65
|
-
elsif cmd[:box] && 1 == argv.size
|
66
|
-
argv[0] = cmd[:box].to_s
|
67
|
-
end
|
68
89
|
|
90
|
+
argv.shift if @env.machine_index.include?(argv[0])
|
91
|
+
argv.shift
|
69
92
|
argv
|
70
93
|
end
|
94
|
+
|
95
|
+
def run_box(cmd)
|
96
|
+
return cmd[:box] if cmd[:box]
|
97
|
+
return @argv[0] if @env.machine_index.include?(@argv[0])
|
98
|
+
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
def run_internal(command)
|
103
|
+
Internal.new(@registry).run(command)
|
104
|
+
end
|
105
|
+
|
106
|
+
def run_script(script, argv)
|
107
|
+
script % argv
|
108
|
+
rescue ArgumentError
|
109
|
+
error = "Not enough parameters to execute \"command[:name]\"!"
|
110
|
+
|
111
|
+
display_error(error)
|
112
|
+
|
113
|
+
nil
|
114
|
+
end
|
71
115
|
end
|
72
116
|
end
|
73
117
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module DevCommands
|
3
|
+
# Handles internal commands and their execution.
|
4
|
+
class Internal
|
5
|
+
def initialize(registry)
|
6
|
+
@registry = registry
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(command)
|
10
|
+
case command
|
11
|
+
when 'help'
|
12
|
+
print_help
|
13
|
+
when 'version'
|
14
|
+
print_version
|
15
|
+
end
|
16
|
+
|
17
|
+
0
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def print_help
|
23
|
+
if @registry.commands.empty?
|
24
|
+
puts 'No commands defined!'
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
display_help_header
|
29
|
+
display_help_commands
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_help_commands
|
33
|
+
pad_to = @registry.commands.keys.map(&:length).max
|
34
|
+
|
35
|
+
@registry.commands.each do |name, command|
|
36
|
+
if command.key?(:desc)
|
37
|
+
puts " #{name.ljust(pad_to)} #{command[:desc]}"
|
38
|
+
else
|
39
|
+
puts " #{name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def display_help_header
|
45
|
+
puts 'Usage: vagrant run [box] <command>'
|
46
|
+
puts ''
|
47
|
+
puts 'Available commands:'
|
48
|
+
end
|
49
|
+
|
50
|
+
def print_version
|
51
|
+
puts "vagrant-devcommands, version #{VERSION}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -2,6 +2,8 @@ module VagrantPlugins
|
|
2
2
|
module DevCommands
|
3
3
|
# Vagrant command registry
|
4
4
|
class Registry
|
5
|
+
RESERVED_COMMANDS = %w(help version)
|
6
|
+
|
5
7
|
attr_accessor :commands
|
6
8
|
|
7
9
|
def initialize
|
@@ -12,36 +14,39 @@ module VagrantPlugins
|
|
12
14
|
contents = commandfile.path.read
|
13
15
|
|
14
16
|
instance_eval(contents)
|
15
|
-
|
17
|
+
end
|
18
|
+
|
19
|
+
def reserved_command?(command)
|
20
|
+
RESERVED_COMMANDS.include?(command)
|
16
21
|
end
|
17
22
|
|
18
23
|
def valid_command?(command)
|
19
|
-
@commands.include? command
|
24
|
+
@commands.include?(command) || reserved_command?(command)
|
20
25
|
end
|
21
26
|
|
22
27
|
private
|
23
28
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
" release.\nPlease update your Commandfile!\n\nMore details: " \
|
29
|
-
'https://github.com/mneudert/vagrant-devcommands'
|
30
|
-
end
|
29
|
+
def command(name, options)
|
30
|
+
return reserved_warning(name) if reserved_command?(name)
|
31
|
+
|
32
|
+
options = { script: options } if options.is_a?(String)
|
31
33
|
|
32
|
-
|
33
|
-
next if @commands.include?(name)
|
34
|
+
return script_warning(name) unless options.key?(:script)
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
@commands[name] = options
|
37
|
+
@commands[name][:name] = name
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def script_warning(name)
|
41
|
+
puts "The command '#{name}' has no script defined to execute."
|
42
|
+
puts 'Your definition of it will be ignored.'
|
43
|
+
puts ''
|
44
|
+
end
|
45
|
+
|
46
|
+
def reserved_warning(name)
|
47
|
+
puts "The command name '#{name}' is reserved for internal usage."
|
48
|
+
puts 'Your definition of it will be ignored.'
|
49
|
+
puts ''
|
45
50
|
end
|
46
51
|
end
|
47
52
|
end
|
data/lib/vagrant/devcommands.rb
CHANGED
@@ -2,10 +2,7 @@ require 'vagrant'
|
|
2
2
|
|
3
3
|
require 'vagrant/devcommands/command'
|
4
4
|
require 'vagrant/devcommands/commandfile'
|
5
|
-
require 'vagrant/devcommands/
|
6
|
-
require 'vagrant/devcommands/help'
|
5
|
+
require 'vagrant/devcommands/internal'
|
7
6
|
require 'vagrant/devcommands/plugin'
|
8
7
|
require 'vagrant/devcommands/registry'
|
9
8
|
require 'vagrant/devcommands/version'
|
10
|
-
|
11
|
-
require 'vagrant/devcommands/_proxy'
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-devcommands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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: 2015-
|
11
|
+
date: 2015-12-13 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
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.2
|
20
|
+
- - "<="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 1.10.6
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.2
|
30
|
+
- - "<="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: 1.10.6
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: coveralls
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,11 +98,9 @@ files:
|
|
92
98
|
- LICENSE.txt
|
93
99
|
- README.md
|
94
100
|
- lib/vagrant/devcommands.rb
|
95
|
-
- lib/vagrant/devcommands/_proxy.rb
|
96
101
|
- lib/vagrant/devcommands/command.rb
|
97
102
|
- lib/vagrant/devcommands/commandfile.rb
|
98
|
-
- lib/vagrant/devcommands/
|
99
|
-
- lib/vagrant/devcommands/help.rb
|
103
|
+
- lib/vagrant/devcommands/internal.rb
|
100
104
|
- lib/vagrant/devcommands/plugin.rb
|
101
105
|
- lib/vagrant/devcommands/registry.rb
|
102
106
|
- lib/vagrant/devcommands/version.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DevCommands
|
3
|
-
# Public interface to define and access commands.
|
4
|
-
class Definer
|
5
|
-
class << self; attr_accessor :commands end
|
6
|
-
|
7
|
-
@commands = {}
|
8
|
-
|
9
|
-
def self.define(name, options)
|
10
|
-
if options.is_a?(String)
|
11
|
-
@commands[name] = { script: options }
|
12
|
-
else
|
13
|
-
if options.include?(:command)
|
14
|
-
options[:script] = options[:command]
|
15
|
-
|
16
|
-
options.delete(:command)
|
17
|
-
end
|
18
|
-
|
19
|
-
@commands[name] = options
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DevCommands
|
3
|
-
# Defines the help output
|
4
|
-
#
|
5
|
-
# Printed when running "vagrant run" without a command
|
6
|
-
class Help
|
7
|
-
def self.display(registry)
|
8
|
-
if registry.commands.empty?
|
9
|
-
puts 'No commands defined!'
|
10
|
-
return
|
11
|
-
end
|
12
|
-
|
13
|
-
display_header
|
14
|
-
display_commands(registry)
|
15
|
-
end
|
16
|
-
|
17
|
-
class << self
|
18
|
-
private
|
19
|
-
|
20
|
-
def display_commands(registry)
|
21
|
-
pad_to = registry.commands.keys.map(&:length).max
|
22
|
-
|
23
|
-
registry.commands.each do |name, command|
|
24
|
-
if command.key?(:desc)
|
25
|
-
puts " #{name.ljust(pad_to)} #{command[:desc]}"
|
26
|
-
else
|
27
|
-
puts " #{name}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def display_header
|
33
|
-
puts 'Usage: vagrant run [box] <command>'
|
34
|
-
puts ''
|
35
|
-
puts 'Available commands:'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|