diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-08-25 12:06:37 -0400 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-08-29 18:13:45 -0500 |
commit | 765002f2d8c29be19371ff9d8ce49121a29cf8bb (patch) | |
tree | c8d7e68875f850a2b1f26ecd1096fa8e8396ef3f | |
parent | 73f91bb04cd75ea2f86282d282f5d5c9e78191fb (diff) | |
download | bundler-765002f2d8c29be19371ff9d8ce49121a29cf8bb.tar.gz |
[CLI] Prettify the output in cli_help
-rw-r--r-- | lib/bundler/cli.rb | 50 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 2 |
2 files changed, 37 insertions, 15 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 97ee5beca0..00f70be48c 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -7,6 +7,8 @@ module Bundler class CLI < Thor require "bundler/cli/common" + package_name "Bundler" + AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze PARSEABLE_COMMANDS = %w[ check config help exec platform show version @@ -71,7 +73,24 @@ module Bundler def cli_help version Bundler.ui.info "\n" - self.class.help(shell) + + primary_commands = %w[install update package exec config help] + + list = self.class.printable_commands(true) + by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] } + utilities = by_name.keys.sort - primary_commands + primary_commands.map! {|name| by_name[name].first } + utilities.map! {|name| by_name[name].first } + + shell.say "Bundler commands:\n\n" + + shell.say " Primary commands:\n" + shell.print_table(primary_commands, :indent => 4, :truncate => true) + shell.say + shell.say " Utilities:\n" + shell.print_table(utilities, :indent => 4, :truncate => true) + shell.say + self.class.send(:class_options_help, shell) end default_task(Bundler.feature_flag.default_cli_command) @@ -437,11 +456,12 @@ module Bundler desc "version", "Prints the bundler's version information" def version - if ARGV.include?("version") + cli_help = current_command.name == "cli_help" + if cli_help || ARGV.include?("version") build_info = " (#{BuildMetadata.built_at} commit #{BuildMetadata.git_commit_sha})" end - if Bundler.feature_flag.print_only_version_number? + if !cli_help && Bundler.feature_flag.print_only_version_number? Bundler.ui.info "#{Bundler::VERSION}#{build_info}" else Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}" @@ -463,7 +483,7 @@ module Bundler end end - desc "viz [OPTIONS]", "Generates a visual dependency graph" + desc "viz [OPTIONS]", "Generates a visual dependency graph", :hide => true long_desc <<-D Viz generates a PNG file of the current Gemfile as a dependency graph. Viz requires the ruby-graphviz gem (and its dependencies). @@ -481,7 +501,7 @@ module Bundler old_gem = instance_method(:gem) - desc "gem GEM [OPTIONS]", "Creates a skeleton for creating a rubygem" + desc "gem NAME [OPTIONS]", "Creates a skeleton for creating a rubygem" method_option :exe, :type => :boolean, :default => false, :aliases => ["--bin", "-b"], :desc => "Generate a binary executable for your library." method_option :coc, :type => :boolean, :desc => "Generate a code of conduct file. Set a default with `bundle config gem.coc true`." method_option :edit, :type => :string, :aliases => "-e", :required => false, :banner => "EDITOR", @@ -520,7 +540,7 @@ module Bundler File.expand_path(File.join(File.dirname(__FILE__), "templates")) end - desc "clean [OPTIONS]", "Cleans up unused gems in your bundler directory" + desc "clean [OPTIONS]", "Cleans up unused gems in your bundler directory", :hide => true method_option "dry-run", :type => :boolean, :default => false, :banner => "Only print out changes, do not clean gems" method_option "force", :type => :boolean, :default => false, :banner => @@ -538,7 +558,7 @@ module Bundler Platform.new(options).run end - desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile" + desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile", :hide => true method_option "source", :type => :string, :banner => "Install gem from the given source" method_option "group", :type => :string, :banner => @@ -618,7 +638,7 @@ module Bundler if Bundler.feature_flag.plugins? require "bundler/cli/plugin" - desc "plugin SUBCOMMAND ...ARGS", "Manage the bundler plugins" + desc "plugin", "Manage the bundler plugins" subcommand "plugin", Plugin end @@ -668,16 +688,20 @@ module Bundler end end + def current_command + _, _, config = @_initializer + config[:current_command] + end + def print_command return unless Bundler.ui.debug? - _, _, config = @_initializer - current_command = config[:current_command] - command_name = current_command.name + cmd = current_command + command_name = cmd.name return if PARSEABLE_COMMANDS.include?(command_name) command = ["bundle", command_name] + args options_to_print = options.dup options_to_print.delete_if do |k, v| - next unless o = current_command.options[k] + next unless o = cmd.options[k] o.default == v end command << Thor::Options.to_switches(options_to_print.sort_by(&:first)).strip @@ -688,8 +712,6 @@ module Bundler def warn_on_outdated_bundler return if Bundler.settings[:disable_version_check] - _, _, config = @_initializer - current_command = config[:current_command] command_name = current_command.name return if PARSEABLE_COMMANDS.include?(command_name) diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 8d851f28a4..259c73a903 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -799,7 +799,7 @@ RSpec.describe "bundle gem" do bundle "gem foo bar baz" expect(last_command.bundler_err).to eq(<<-E.strip) ERROR: "bundle gem" was called with arguments ["foo", "bar", "baz"] -Usage: "bundle gem GEM [OPTIONS]" +Usage: "bundle gem NAME [OPTIONS]" E end end |