diff options
author | Colby Swandale <colby@taplaboratories.com> | 2017-08-04 13:52:03 +1000 |
---|---|---|
committer | Colby Swandale <colby@taplaboratories.com> | 2017-08-04 19:08:45 +1000 |
commit | 2c5dc254bbadd89e9a601c2f21976c733efdc1cb (patch) | |
tree | 1873a8e4e6a39ec23a4a4ad3638ea91fa9db94d3 | |
parent | dedaedcf727af38e78c51b95624d8dea3515529b (diff) | |
download | bundler-2c5dc254bbadd89e9a601c2f21976c733efdc1cb.tar.gz |
implement new list command taken from bundler show
-rw-r--r-- | lib/bundler/cli.rb | 13 | ||||
-rw-r--r-- | lib/bundler/cli/list.rb | 17 | ||||
-rw-r--r-- | lib/bundler/feature_flag.rb | 1 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 | ||||
-rw-r--r-- | man/bundle-config.ronn | 2 | ||||
-rw-r--r-- | man/bundle-list.ronn | 10 | ||||
-rw-r--r-- | spec/commands/list_spec.rb | 33 |
7 files changed, 76 insertions, 1 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index a1ad3055ca..3cefc90970 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -261,7 +261,18 @@ module Bundler Show.new(options, gem_name).run end # TODO: 2.0 remove `bundle show` - map %w[list] => "show" + + if Bundler.feature_flag.list_command? + desc "list", "list all gems in the bundle" + def list + require "bundler/cli/list" + List.new.run + end + + map %w[ls] => "list" + else + map %w[list] => "show" + end desc "info GEM [OPTIONS]", "Show information for the given gem" method_option "path", :type => :boolean, :banner => "Print full path to gem" diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb new file mode 100644 index 0000000000..623e2bc076 --- /dev/null +++ b/lib/bundler/cli/list.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Bundler + class CLI::List + def run + specs = Bundler.load.specs.reject {|s| s.name == "bundler" } + + return Bundler.ui.info "No gems in the Gemfile" if specs.empty? + Bundler.ui.info "Gems included by the bundle:" + specs.sort_by(&:name).each do |s| + Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})" + end + + Bundler.ui.info "Use `bundle info` to print more detailed information about a gem" + end + end +end diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 67b89d89d3..2dedbbabbc 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -48,6 +48,7 @@ module Bundler settings_flag(:unlock_source_unlocks_spec) { !bundler_2_mode? } settings_flag(:update_requires_all_flag) { bundler_2_mode? } settings_flag(:default_install_uses_path) { bundler_2_mode? } + settings_flag(:list_command) { bundler_2_mode? } settings_option(:default_cli_command) { bundler_2_mode? ? :cli_help : :install } diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 15168b42e4..23469fc7c8 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -34,6 +34,7 @@ module Bundler global_gem_cache ignore_messages init_gems_rb + list_command lockfile_uses_separate_rubygems_sources major_deprecations no_install diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index dd315b9955..87d1013129 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -193,6 +193,8 @@ learn more about their operation in [bundle install(1)][bundle-install]. Generate a `gems.rb` instead of a `Gemfile` when running `bundle init`. * `jobs` (`BUNDLE_JOBS`): The number of gems Bundler can install in parallel. Defaults to 1. +* `list_command` (`BUNDLE_LIST_COMMAND`) + Enable new list command feature * `major_deprecations` (`BUNDLE_MAJOR_DEPRECATIONS`): Whether Bundler should print deprecation warnings for behavior that will be changed in the next major version. diff --git a/man/bundle-list.ronn b/man/bundle-list.ronn new file mode 100644 index 0000000000..3a883bf5ff --- /dev/null +++ b/man/bundle-list.ronn @@ -0,0 +1,10 @@ +bundle-list(1) -- List all the gems in the bundle +========================================================================= + +## SYNOPSIS + +`bundle list` + +## DESCRIPTION + +Prints a list of all the gems in the bundle including their version diff --git a/spec/commands/list_spec.rb b/spec/commands/list_spec.rb new file mode 100644 index 0000000000..850ca24dc2 --- /dev/null +++ b/spec/commands/list_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +RSpec.describe "bundle list", :bundler => "2" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + end + + context "when no gems are in the gemfile" do + before do + install_gemfile <<-G + source "file://#{gem_repo1}" + G + end + + it "prints message saying no gems are in the bundle" do + bundle "list" + expect(out).to include("No gems in the Gemfile") + end + end + + it "lists gems installed in the bundle" do + bundle "list" + expect(out).to include(" * rack (1.0.0)") + end + + it "aliases the ls command to list" do + bundle "ls" + expect(out).to include("Gems included by the bundle") + end +end |