From 55adfc3b824b833dcdf73d6cabba7a1e6148d740 Mon Sep 17 00:00:00 2001 From: hieptranquoc Date: Tue, 2 Oct 2018 01:09:11 +0700 Subject: [PATCH] @ #484 | should make vagrant plugin can install by command --- lib/teracy-dev/plugin.rb | 57 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/teracy-dev/plugin.rb b/lib/teracy-dev/plugin.rb index 2f047adb..8e937005 100644 --- a/lib/teracy-dev/plugin.rb +++ b/lib/teracy-dev/plugin.rb @@ -17,7 +17,11 @@ def self.sync(plugins) if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed' logger.info("installing plugin: #{plugin}") - plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin)) + unless plugin['plugin_vars'].nil? + install_plugin_by_cmd(plugin, logger) + else + plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin)) + end reload_required = true end @@ -37,5 +41,56 @@ def self.sync(plugins) def self.installed?(plugin_name) return Vagrant.has_plugin?(plugin_name) end + + private + + def self.cmd_install_plugin(plugin_vars, plugin_to_install, command_opts) + cmd = '' + + plugin_vars.each do |key, val| + key = key.to_s.upcase + val = val.to_s + + cmd << "#{key}='#{val}' " + end + + cmd << "vagrant plugin install #{plugin_to_install}" + + unless command_opts.empty? + command_opts.each do |key, val| + key = key.to_s + val = val.to_s + + if val.empty? + cmd << " --#{key}" + else + cmd << " --#{key}='#{val}'" + end + end + end + + cmd + end + + def self.install_plugin_by_cmd(plugin, logger) + logger.info("installing vagrant plugin by command...") + plugin_to_install = plugin['name'] + + unless plugin_to_install.empty? + command_opts = '' + command_opts = plugin['command_opts'] if !plugin['command_opts'].nil? + + cmd = cmd_install_plugin(plugin['plugin_vars'], plugin_to_install, command_opts) + logger.info("Command install: #{cmd}") + + if cmd.empty? + abort "Installation of plugin has failed. Command is empty..." + end + + unless system cmd + abort "Installation of plugin has failed. Aborting..." + end + end + end end end