summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfotanus <fotanus@gmail.com>2017-05-24 16:31:30 -0300
committerfotanus <fotanus@gmail.com>2017-05-30 14:27:29 -0300
commita08d08eb9854435ba6d5ef513d95e295ab19e8a6 (patch)
tree97911883bb2772c270f0057d3a287188e0a541e7
parentbf26b5515926c51008f2fe9e9d0054260d482e74 (diff)
downloadbundler-a08d08eb9854435ba6d5ef513d95e295ab19e8a6.tar.gz
implement command `bundle plugin list`
-rw-r--r--lib/bundler/cli/plugin.rb5
-rw-r--r--lib/bundler/plugin.rb20
-rw-r--r--lib/bundler/plugin/index.rb8
-rw-r--r--spec/bundler/plugin_spec.rb25
4 files changed, 58 insertions, 0 deletions
diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb
index 277822dafc..2019a4e10c 100644
--- a/lib/bundler/cli/plugin.rb
+++ b/lib/bundler/cli/plugin.rb
@@ -19,5 +19,10 @@ module Bundler
def install(*plugins)
Bundler::Plugin.install(plugins, options)
end
+
+ desc "list", "List the installed plugins and available commands"
+ def list
+ Bundler::Plugin.list
+ end
end
end
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 66f485ef8e..1e9c40fe49 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -45,6 +45,26 @@ module Bundler
Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}"
end
+ # List installed plugins and commands
+ #
+ def list
+ installed_plugins = index.installed_plugins
+ if installed_plugins.any?
+ output = String.new
+ installed_plugins.each do |plugin|
+ output << "#{plugin}\n"
+ output << "-----\n"
+ index.plugin_commands(plugin).each do |command|
+ output << " #{command}\n"
+ end
+ output << "\n"
+ end
+ else
+ output = "No plugins installed"
+ end
+ Bundler.ui.info output
+ end
+
# Evaluates the Gemfile with a limited DSL and installs the plugins
# specified by plugin method
#
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb
index 8dde072f16..b9328d3177 100644
--- a/lib/bundler/plugin/index.rb
+++ b/lib/bundler/plugin/index.rb
@@ -95,6 +95,14 @@ module Bundler
@plugin_paths[name]
end
+ def installed_plugins
+ @plugin_paths.keys
+ end
+
+ def plugin_commands(plugin)
+ @commands.find_all {|_, n| n == plugins }.map(&:first)
+ end
+
def source?(source)
@sources.key? source
end
diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb
index 9796b580a3..40e71ab578 100644
--- a/spec/bundler/plugin_spec.rb
+++ b/spec/bundler/plugin_spec.rb
@@ -32,6 +32,31 @@ RSpec.describe Bundler::Plugin do
allow(index).to receive(:register_plugin)
end
+ describe "list command" do
+ let(:opts) { { "version" => "~> 1.0", "source" => "foo" } }
+
+ context "when no plugins are installed" do
+ before { allow(index).to receive(:installed_plugins) { [] } }
+ it "outputs no plugins installed" do
+ expect(Bundler.ui).to receive(:info).with("No plugins installed")
+ subject.list
+ end
+ end
+
+ context "with installed plugins" do
+ before do
+ allow(index).to receive(:installed_plugins) { %w[plug1 plug2] }
+ allow(index).to receive(:plugin_commands).with("plug1") { %w[c11 c12] }
+ allow(index).to receive(:plugin_commands).with("plug2") { %w[c21 c22] }
+ end
+ it "list plugins followed by commands" do
+ expected_output = "plug1\n-----\n c11\n c12\n\nplug2\n-----\n c21\n c22\n\n"
+ expect(Bundler.ui).to receive(:info).with(expected_output)
+ subject.list
+ end
+ end
+ end
+
describe "install command" do
let(:opts) { { "version" => "~> 1.0", "source" => "foo" } }