vagrant-devcommands 0.7.2 → 0.8.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 +6 -0
- data/README.md +106 -12
- data/lib/vagrant/devcommands/command.rb +54 -71
- data/lib/vagrant/devcommands/{command_file.rb → commandfile.rb} +2 -4
- data/lib/vagrant/devcommands/help_printer/chain.rb +62 -0
- data/lib/vagrant/devcommands/help_printer/command.rb +78 -0
- data/lib/vagrant/devcommands/internal_command/help.rb +36 -73
- data/lib/vagrant/devcommands/internal_spec.rb +6 -4
- data/lib/vagrant/devcommands/messages.rb +23 -13
- data/lib/vagrant/devcommands/model/chain.rb +28 -0
- data/lib/vagrant/devcommands/model/command.rb +107 -0
- data/lib/vagrant/devcommands/plugin.rb +1 -1
- data/lib/vagrant/devcommands/registry.rb +72 -9
- data/lib/vagrant/devcommands/runner/chain.rb +44 -0
- data/lib/vagrant/devcommands/runner/command.rb +70 -0
- data/lib/vagrant/devcommands/runner/internal_command.rb +46 -0
- data/lib/vagrant/devcommands/synopsis.rb +6 -0
- data/lib/vagrant/devcommands/util.rb +43 -2
- data/lib/vagrant/devcommands/version.rb +1 -1
- data/lib/vagrant/devcommands.rb +13 -4
- data/locales/en.yml +33 -3
- metadata +12 -20
- data/lib/vagrant/devcommands/command_def.rb +0 -92
- data/lib/vagrant/devcommands/internal.rb +0 -26
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module DevCommands
|
|
3
|
+
module Runner
|
|
4
|
+
# Chain runner
|
|
5
|
+
class Chain
|
|
6
|
+
def initialize(plugin, argv, env, registry)
|
|
7
|
+
@plugin = plugin
|
|
8
|
+
@argv = argv
|
|
9
|
+
@env = env
|
|
10
|
+
@registry = registry
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run(chain)
|
|
14
|
+
retval = 0
|
|
15
|
+
|
|
16
|
+
chain.commands.each do |command_def|
|
|
17
|
+
runnable = runnable_for(command_def)
|
|
18
|
+
runnable_argv = argv_for(command_def)
|
|
19
|
+
|
|
20
|
+
runner = Command.new(@plugin, runnable_argv, @env, @registry)
|
|
21
|
+
retval = runner.run(runnable)
|
|
22
|
+
|
|
23
|
+
break if retval.nonzero? && chain.break_on_error?
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
retval
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def argv_for(command_def)
|
|
32
|
+
return @argv unless command_def.key?(:argv)
|
|
33
|
+
return @argv unless command_def[:argv].is_a?(Array)
|
|
34
|
+
|
|
35
|
+
@argv + command_def[:argv]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def runnable_for(command_def)
|
|
39
|
+
@registry.commands[command_def[:command]]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module DevCommands
|
|
3
|
+
module Runner
|
|
4
|
+
# Command runner
|
|
5
|
+
class Command
|
|
6
|
+
UTIL = VagrantPlugins::DevCommands::Util
|
|
7
|
+
|
|
8
|
+
def initialize(plugin, argv, env, registry)
|
|
9
|
+
@plugin = plugin
|
|
10
|
+
@argv = argv
|
|
11
|
+
@env = env
|
|
12
|
+
@registry = registry
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def run(command)
|
|
16
|
+
argv = run_argv
|
|
17
|
+
box = run_box(command)
|
|
18
|
+
script = run_script(command, argv)
|
|
19
|
+
|
|
20
|
+
return 2 unless script
|
|
21
|
+
|
|
22
|
+
@plugin.proxy_with_target_vms(box, single_target: true) do |vm|
|
|
23
|
+
env = vm.action(:ssh_run,
|
|
24
|
+
ssh_opts: { extra_args: ['-q'] },
|
|
25
|
+
ssh_run_command: script)
|
|
26
|
+
|
|
27
|
+
return env[:ssh_run_exit_status] || 0
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def run_argv
|
|
34
|
+
argv = @argv.dup
|
|
35
|
+
|
|
36
|
+
argv.shift if UTIL.machine_name?(argv[0].to_s, @env.machine_index)
|
|
37
|
+
argv.shift
|
|
38
|
+
argv
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def run_box(cmd)
|
|
42
|
+
box = nil
|
|
43
|
+
box = cmd.box.to_s if cmd.box
|
|
44
|
+
box = @argv[0] if UTIL.machine_name?(@argv[0].to_s,
|
|
45
|
+
@env.machine_index)
|
|
46
|
+
|
|
47
|
+
box
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def run_script(command, argv)
|
|
51
|
+
command.run_script(argv)
|
|
52
|
+
rescue KeyError => e
|
|
53
|
+
param = e.message.match(/{(.+)}/).captures.first
|
|
54
|
+
|
|
55
|
+
script_error(command.name, 'missing_parameter', param)
|
|
56
|
+
rescue OptionParser::InvalidOption => e
|
|
57
|
+
script_error(command.name, 'invalid_parameter', e.args.first)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def script_error(command, type, detail)
|
|
61
|
+
error = I18n.t("vagrant_devcommands.runner.#{type}", detail: detail)
|
|
62
|
+
|
|
63
|
+
raise I18n.t('vagrant_devcommands.runner.script_error',
|
|
64
|
+
command: command,
|
|
65
|
+
error: error)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module VagrantPlugins
|
|
2
|
+
module DevCommands
|
|
3
|
+
module Runner
|
|
4
|
+
# Internal command runner
|
|
5
|
+
class InternalCommand
|
|
6
|
+
NAMESPACE_CMD = VagrantPlugins::DevCommands::InternalCommand
|
|
7
|
+
NAMESPACE_MODEL = VagrantPlugins::DevCommands::Model
|
|
8
|
+
NAMESPACE_SPEC = VagrantPlugins::DevCommands::InternalSpec
|
|
9
|
+
UTIL = VagrantPlugins::DevCommands::Util
|
|
10
|
+
|
|
11
|
+
COMMANDS = {
|
|
12
|
+
'help' => NAMESPACE_MODEL::Command.new(NAMESPACE_SPEC::HELP),
|
|
13
|
+
'version' => NAMESPACE_MODEL::Command.new(NAMESPACE_SPEC::VERSION)
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
def initialize(plugin, argv, env, registry)
|
|
17
|
+
@plugin = plugin
|
|
18
|
+
@argv = argv
|
|
19
|
+
@env = env
|
|
20
|
+
@registry = registry
|
|
21
|
+
|
|
22
|
+
@internal = {
|
|
23
|
+
'help' => NAMESPACE_CMD::Help.new(env, registry),
|
|
24
|
+
'version' => NAMESPACE_CMD::Version.new(env)
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run(command, args = nil)
|
|
29
|
+
return nil unless @internal.key?(command)
|
|
30
|
+
|
|
31
|
+
@internal[command].execute(args || run_argv)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def run_argv
|
|
37
|
+
argv = @argv.dup
|
|
38
|
+
|
|
39
|
+
argv.shift if UTIL.machine_name?(argv[0].to_s, @env.machine_index)
|
|
40
|
+
argv.shift
|
|
41
|
+
argv
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -2,15 +2,56 @@ module VagrantPlugins
|
|
|
2
2
|
module DevCommands
|
|
3
3
|
# Utility module
|
|
4
4
|
class Util
|
|
5
|
+
def self.argv_command(argv, env)
|
|
6
|
+
return nil if argv.empty?
|
|
7
|
+
|
|
8
|
+
command = argv[0].to_s
|
|
9
|
+
command = argv[1].to_s if machine_name?(command, env.machine_index)
|
|
10
|
+
|
|
11
|
+
command
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.collect_flags(flags)
|
|
15
|
+
flags.collect do |key, _opts|
|
|
16
|
+
"[--#{key}]"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.collect_mandatory_params(params)
|
|
21
|
+
params.collect do |key, opts|
|
|
22
|
+
"--#{key}=<#{key}>" unless opts[:optional]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.collect_optional_params(params)
|
|
27
|
+
params.collect do |key, opts|
|
|
28
|
+
"[--#{key}=<#{key}>]" if opts[:optional]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
5
32
|
def self.machine_name?(name, machine_index)
|
|
6
33
|
machine_index.any? { |machine| name == machine.name }
|
|
7
34
|
end
|
|
8
35
|
|
|
36
|
+
def self.max_pad(items_list)
|
|
37
|
+
paddings = items_list.map do |items|
|
|
38
|
+
if items.nil? || items.empty?
|
|
39
|
+
0
|
|
40
|
+
else
|
|
41
|
+
pad_to(items)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
paddings.max
|
|
46
|
+
end
|
|
47
|
+
|
|
9
48
|
def self.pad_to(items)
|
|
10
|
-
items.keys.
|
|
49
|
+
items = items.keys unless items.is_a?(Array)
|
|
50
|
+
|
|
51
|
+
items.map(&:length).max
|
|
11
52
|
end
|
|
12
53
|
|
|
13
|
-
def self.padded_columns(pad_to, left, right)
|
|
54
|
+
def self.padded_columns(pad_to, left, right = nil)
|
|
14
55
|
left = left.to_s unless left.is_a?(String)
|
|
15
56
|
right = right.to_s unless right.is_a?(String)
|
|
16
57
|
|
data/lib/vagrant/devcommands.rb
CHANGED
|
@@ -3,17 +3,26 @@ require 'vagrant'
|
|
|
3
3
|
I18n.load_path << File.expand_path('../../../locales/en.yml', __FILE__)
|
|
4
4
|
I18n.reload!
|
|
5
5
|
|
|
6
|
+
require 'vagrant/devcommands/synopsis'
|
|
7
|
+
require 'vagrant/devcommands/version'
|
|
8
|
+
|
|
6
9
|
require 'vagrant/devcommands/internal_spec'
|
|
7
10
|
require 'vagrant/devcommands/messages'
|
|
8
11
|
require 'vagrant/devcommands/util'
|
|
9
12
|
|
|
13
|
+
require 'vagrant/devcommands/model/chain'
|
|
14
|
+
require 'vagrant/devcommands/model/command'
|
|
15
|
+
|
|
16
|
+
require 'vagrant/devcommands/help_printer/chain'
|
|
17
|
+
require 'vagrant/devcommands/help_printer/command'
|
|
10
18
|
require 'vagrant/devcommands/internal_command/help'
|
|
11
19
|
require 'vagrant/devcommands/internal_command/version'
|
|
12
20
|
|
|
21
|
+
require 'vagrant/devcommands/runner/chain'
|
|
22
|
+
require 'vagrant/devcommands/runner/command'
|
|
23
|
+
require 'vagrant/devcommands/runner/internal_command'
|
|
24
|
+
|
|
13
25
|
require 'vagrant/devcommands/command'
|
|
14
|
-
require 'vagrant/devcommands/
|
|
15
|
-
require 'vagrant/devcommands/command_file'
|
|
16
|
-
require 'vagrant/devcommands/internal'
|
|
26
|
+
require 'vagrant/devcommands/commandfile'
|
|
17
27
|
require 'vagrant/devcommands/plugin'
|
|
18
28
|
require 'vagrant/devcommands/registry'
|
|
19
|
-
require 'vagrant/devcommands/version'
|
data/locales/en.yml
CHANGED
|
@@ -2,11 +2,41 @@ en:
|
|
|
2
2
|
vagrant_devcommands:
|
|
3
3
|
internal:
|
|
4
4
|
help:
|
|
5
|
-
desc: "
|
|
5
|
+
desc: "get some plugin help"
|
|
6
6
|
help: |-
|
|
7
7
|
Display the help of the command given as the first argument if defined.
|
|
8
8
|
Just like this help for the help command!
|
|
9
|
+
usage: "Usage: %{what}"
|
|
9
10
|
|
|
10
11
|
version:
|
|
11
|
-
desc: "
|
|
12
|
-
help: "Displays the currently installed version the plugin you are using right now."
|
|
12
|
+
desc: "get currently installed plugin version"
|
|
13
|
+
help: "Displays the currently installed version of the plugin you are using right now."
|
|
14
|
+
|
|
15
|
+
message:
|
|
16
|
+
chain_no_help: "No detailed help for this chain available."
|
|
17
|
+
command_no_help: "No detailed help for this command available."
|
|
18
|
+
missing_commandfile: "Missing Commandfile"
|
|
19
|
+
no_commands: "No commands defined!"
|
|
20
|
+
plugin_readme: |-
|
|
21
|
+
For detailed plugin usage information please read
|
|
22
|
+
the README.md at the original source location:
|
|
23
|
+
>>> https://github.com/mneudert/vagrant-devcommands
|
|
24
|
+
A copy of this file should be locally available at:
|
|
25
|
+
>>> %{readme}
|
|
26
|
+
plugin_usage: |-
|
|
27
|
+
Usage: vagrant run [box] <command>
|
|
28
|
+
Help: vagrant run help <command>
|
|
29
|
+
|
|
30
|
+
registry:
|
|
31
|
+
chain_ignored: "Your chain definition will be ignored in favor of the command"
|
|
32
|
+
conflict: "The name '%{name}' is used for both a command and a chain."
|
|
33
|
+
def_ignored: "Your definition of it will be ignored."
|
|
34
|
+
empty_chain: "The chain '%{name}' has no commands associated."
|
|
35
|
+
missing_command: "The chain '%{chain}' is using at least one unknown command ('%{command}')."
|
|
36
|
+
no_script: "The command '%{name}' has no script defined to execute."
|
|
37
|
+
reserved: "The command name '%{name}' is reserved for internal usage."
|
|
38
|
+
|
|
39
|
+
runner:
|
|
40
|
+
invalid_parameter: "invalid parameter '%{detail}'"
|
|
41
|
+
missing_parameter: "missing parameter '%{detail}'"
|
|
42
|
+
script_error: "Could not execute %{command}: %{error}"
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vagrant-devcommands
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.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-
|
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: bundler
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - '='
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.12.5
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - '='
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.12.5
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: coveralls
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -93,15 +79,21 @@ files:
|
|
|
93
79
|
- README.md
|
|
94
80
|
- lib/vagrant/devcommands.rb
|
|
95
81
|
- lib/vagrant/devcommands/command.rb
|
|
96
|
-
- lib/vagrant/devcommands/
|
|
97
|
-
- lib/vagrant/devcommands/
|
|
98
|
-
- lib/vagrant/devcommands/
|
|
82
|
+
- lib/vagrant/devcommands/commandfile.rb
|
|
83
|
+
- lib/vagrant/devcommands/help_printer/chain.rb
|
|
84
|
+
- lib/vagrant/devcommands/help_printer/command.rb
|
|
99
85
|
- lib/vagrant/devcommands/internal_command/help.rb
|
|
100
86
|
- lib/vagrant/devcommands/internal_command/version.rb
|
|
101
87
|
- lib/vagrant/devcommands/internal_spec.rb
|
|
102
88
|
- lib/vagrant/devcommands/messages.rb
|
|
89
|
+
- lib/vagrant/devcommands/model/chain.rb
|
|
90
|
+
- lib/vagrant/devcommands/model/command.rb
|
|
103
91
|
- lib/vagrant/devcommands/plugin.rb
|
|
104
92
|
- lib/vagrant/devcommands/registry.rb
|
|
93
|
+
- lib/vagrant/devcommands/runner/chain.rb
|
|
94
|
+
- lib/vagrant/devcommands/runner/command.rb
|
|
95
|
+
- lib/vagrant/devcommands/runner/internal_command.rb
|
|
96
|
+
- lib/vagrant/devcommands/synopsis.rb
|
|
105
97
|
- lib/vagrant/devcommands/util.rb
|
|
106
98
|
- lib/vagrant/devcommands/version.rb
|
|
107
99
|
- locales/en.yml
|
|
@@ -126,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
118
|
version: '0'
|
|
127
119
|
requirements: []
|
|
128
120
|
rubyforge_project:
|
|
129
|
-
rubygems_version: 2.
|
|
121
|
+
rubygems_version: 2.6.6
|
|
130
122
|
signing_key:
|
|
131
123
|
specification_version: 4
|
|
132
124
|
summary: Runs vagrant commands from a Commandfile
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
|
-
|
|
3
|
-
module VagrantPlugins
|
|
4
|
-
module DevCommands
|
|
5
|
-
# Definition of an executable command
|
|
6
|
-
class CommandDef
|
|
7
|
-
attr_reader :name
|
|
8
|
-
attr_reader :parameters
|
|
9
|
-
attr_reader :script
|
|
10
|
-
|
|
11
|
-
attr_reader :box
|
|
12
|
-
attr_reader :desc
|
|
13
|
-
attr_reader :help
|
|
14
|
-
attr_reader :usage
|
|
15
|
-
|
|
16
|
-
def initialize(spec)
|
|
17
|
-
@name = spec[:name]
|
|
18
|
-
@parameters = spec[:parameters]
|
|
19
|
-
@script = spec[:script]
|
|
20
|
-
|
|
21
|
-
@box = spec[:box]
|
|
22
|
-
@desc = spec[:desc]
|
|
23
|
-
@help = spec[:help]
|
|
24
|
-
@usage = spec[:usage]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def run_script(argv)
|
|
28
|
-
script = @script
|
|
29
|
-
script = script.call if script.is_a?(Proc)
|
|
30
|
-
|
|
31
|
-
opts = {}
|
|
32
|
-
opts = parse_argv(argv) if @parameters
|
|
33
|
-
|
|
34
|
-
(script % opts).strip
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def escape_option_values(options)
|
|
40
|
-
@parameters.each do |key, conf|
|
|
41
|
-
next if conf[:escape].nil?
|
|
42
|
-
|
|
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}")
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
options
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def options_with_defaults
|
|
53
|
-
options = {}
|
|
54
|
-
|
|
55
|
-
@parameters.each do |key, conf|
|
|
56
|
-
options[key] = '' if conf[:optional]
|
|
57
|
-
options[key] = conf[:default] unless conf[:default].nil?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
options
|
|
61
|
-
end
|
|
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
|
-
|
|
77
|
-
def wrap_option_values(options)
|
|
78
|
-
@parameters.each do |key, conf|
|
|
79
|
-
next if conf[:wrap].nil?
|
|
80
|
-
|
|
81
|
-
if conf[:default].nil?
|
|
82
|
-
next if options[key].nil? || options[key].empty?
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
options[key] = conf[:wrap] % options[key]
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
options
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|