Skip to content

Commit

Permalink
@ #484 | should make vagrant plugin can install by command
Browse files Browse the repository at this point in the history
  • Loading branch information
hieptranquoc committed Oct 1, 2018
1 parent c91607a commit 55adfc3
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion lib/teracy-dev/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 55adfc3

Please sign in to comment.