Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Redirects any usage of --help flag for a command to that command's man page #4178

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion exe/bundle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ end
require "bundler/friendly_errors"
Bundler.with_friendly_errors do
require "bundler/cli"
Bundler::CLI.start(ARGV, :debug => true)

# Allow any command to use --help flag to show help for that command
help_flags = %w(--help -h)
help_flag_used = ARGV.any? {|a| help_flags.include? a }
args = help_flag_used ? Bundler::CLI.reformatted_help_args(ARGV) : ARGV

Bundler::CLI.start(args, :debug => true)
end
13 changes: 13 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@ def env
Env.new.write($stdout)
end

# Reformat the arguments passed to bundle that include a --help flag
# into the corresponding `bundle help #{command}` call
def self.reformatted_help_args(args)
bundler_commands = all_commands.keys
command = args.select {|a| bundler_commands.include? a }
if command.empty?
abort("Could not find command \"#{args.join(" ")}\".")
else
command = command.first
end
["help", command]
end

private

# Automatically invoke `bundle install` and resume if
Expand Down
35 changes: 35 additions & 0 deletions spec/commands/help_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,39 @@
expect(exitstatus).to be_zero if exitstatus
expect(out).to eq("--help")
end

it "is called when the --help flag is used after the command" do
fake_man!

bundle "install --help"
expect(out).to eq(%(["#{root}/lib/bundler/man/bundle-install"]))
end

it "is called when the --help flag is used before the command" do
fake_man!

bundle "--help install"
expect(out).to eq(%(["#{root}/lib/bundler/man/bundle-install"]))
end

it "is called when the -h flag is used before the command" do
fake_man!

bundle "-h install"
expect(out).to eq(%(["#{root}/lib/bundler/man/bundle-install"]))
end

it "is called when the -h flag is used after the command" do
fake_man!

bundle "install -h"
expect(out).to eq(%(["#{root}/lib/bundler/man/bundle-install"]))
end

it "has helpful output when using --help flag for a non-existent command" do
fake_man!

bundle "instill -h", :expect_err => true
expect(err).to include('Could not find command "instill -h --no-color".')
end
end