Skip to content

Commit

Permalink
Rename plugin_list to plugins_arg to make it clearer it is user submi…
Browse files Browse the repository at this point in the history
…tted content.

Fixes elastic#2946
  • Loading branch information
ph authored and jordansissel committed Apr 9, 2015
1 parent 244be5c commit 25926f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions lib/logstash/pluginmanager/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require "fileutils"

class LogStash::PluginManager::Install < LogStash::PluginManager::Command
parameter "[PLUGIN] ...", "plugin name(s) or file"
parameter "[PLUGIN] ...", "plugin name(s) or file", :attribute_name => :plugins_arg
option "--version", "VERSION", "version of the plugin to install"
option "--[no-]verify", :flag, "verify plugin validity before installation", :default => true
option "--development", :flag, "install all development dependencies of currently installed plugins", :default => false
Expand All @@ -38,11 +38,11 @@ def execute
private
def validate_cli_options!
if development?
signal_usage_error("Cannot specify plugin(s) with --development, it will add the development dependencies of the currently installed plugins") unless plugin_list.empty?
signal_usage_error("Cannot specify plugin(s) with --development, it will add the development dependencies of the currently installed plugins") unless plugins_arg.empty?
else
signal_usage_error("No plugin specified") if plugin_list.empty? && verify?
signal_usage_error("No plugin specified") if plugins_arg.empty? && verify?
# TODO: find right syntax to allow specifying list of plugins with optional version specification for each
signal_usage_error("Only 1 plugin name can be specified with --version") if version && plugin_list.size > 1
signal_usage_error("Only 1 plugin name can be specified with --version") if version && plugins_arg.size > 1
end
signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless ::File.writable?(LogStash::Environment::GEMFILE_PATH)
end
Expand Down Expand Up @@ -73,12 +73,12 @@ def plugins_development_gems
end

def plugins_gems
version ? [plugin_list << version] : plugin_list.map { |plugin| [plugin, nil] }
version ? [plugins_arg << version] : plugins_arg.map { |plugin| [plugin, nil] }
end

# install_list will be an array of [plugin name, version, options] tuples, version it
# can be nil at this point we know that plugin_list is not empty and if the
# --version is specified there is only one plugin in plugin_list
# can be nil at this point we know that plugins_arg is not empty and if the
# --version is specified there is only one plugin in plugins_arg
#
def install_gems_list!(install_list)
# If something goes wrong during the installation `LogStash::Gemfile` will restore a backup version.
Expand Down Expand Up @@ -114,17 +114,17 @@ def install_gems_list!(install_list)
# Bundler 2.0, will have support for plugins source we could create a .gem source
# to support it.
def extract_local_gems_plugins
plugin_list.collect do |plugin|
plugins_arg.collect do |plugin|
package, path = LogStash::Bundler.unpack(plugin, LogStash::Environment::LOCAL_GEM_PATH)
[package.spec.name, package.spec.version, { :path => relative_path(path) }]
end
end

# We cannot install both .gem and normal plugin in one call of `plugin install`
def local_gems?
return false if plugin_list.empty?
return false if plugins_arg.empty?

local_gem = plugin_list.collect { |plugin| ::File.extname(plugin) == ".gem" }.uniq
local_gem = plugins_arg.collect { |plugin| ::File.extname(plugin) == ".gem" }.uniq

if local_gem.size == 1
return local_gem.first
Expand Down
10 changes: 5 additions & 5 deletions lib/logstash/pluginmanager/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
require "logstash/bundler"

class LogStash::PluginManager::Update < LogStash::PluginManager::Command
parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version"
parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version", :attribute_name => :plugins_arg

def execute
local_gems = gemfile.locally_installed_gems

if update_all? || !local_gems.empty?
error_plugin_that_use_path!(local_gems)
else
plugins_with_path = plugin_list & local_gems
plugins_with_path = plugins_arg & local_gems
error_plugin_that_use_path!(plugins_with_path) if plugins_with_path.size > 0
end

Expand All @@ -30,7 +30,7 @@ def error_plugin_that_use_path!(plugins)
end

def update_all?
plugin_list.size == 0
plugins_arg.size == 0
end

def update_gems!
Expand Down Expand Up @@ -67,9 +67,9 @@ def plugins_to_update(previous_gem_specs_map)
if update_all?
previous_gem_specs_map.values.map{|spec| spec.name}
else
not_installed = plugin_list.select{|plugin| !previous_gem_specs_map.has_key?(plugin.downcase)}
not_installed = plugins_arg.select{|plugin| !previous_gem_specs_map.has_key?(plugin.downcase)}
signal_error("Plugin #{not_installed.join(', ')} is not installed so it cannot be updated, aborting") unless not_installed.empty?
plugin_list
plugins_arg
end
end

Expand Down

0 comments on commit 25926f7

Please sign in to comment.