diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-10-20 14:03:11 +0200 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-10-30 10:04:18 +0100 |
commit | e983b2946ffe30c9f8437dfe5679eeab1abaeec0 (patch) | |
tree | 91f63f62c095d6f6e299c7d444c0a92ed437ba4d /lib | |
parent | f7212773160d00d88f58c24147584cada0da5187 (diff) | |
download | bundler-fix_help_with_command_aliases.tar.gz |
Fix help with command aliasesfix_help_with_command_aliases
When using the `-h` flag with command aliases, bundler was showing a
default help page instead of our manual, so that for example, `bundle
help install` and `bundle install --help` output would be inconstent
with `bundle i --help`.
This commit fixes that.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index ea2d5c9de3..bacbb8dbde 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -36,8 +36,22 @@ module Bundler end end + def self.all_aliases + @all_aliases ||= begin + command_aliases = {} + + COMMAND_ALIASES.each do |name, aliases| + Array(aliases).each do |one_alias| + command_aliases[one_alias] = name + end + end + + command_aliases + end + end + def self.aliases_for(command_name) - COMMAND_ALIASES.slice(command_name).invert + COMMAND_ALIASES.select {|k, _| k == command_name }.invert end def initialize(*args) @@ -694,13 +708,17 @@ module Bundler # 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 + bundler_commands = (COMMAND_ALIASES.keys + COMMAND_ALIASES.values).flatten + help_flags = %w[--help -h] exec_commands = ["exec"] + COMMAND_ALIASES["exec"] help_used = args.index {|a| help_flags.include? a } exec_used = args.index {|a| exec_commands.include? a } + command = args.find {|a| bundler_commands.include? a } + command = all_aliases[command] if all_aliases[command] + if exec_used && help_used if exec_used + help_used == 1 %w[help exec] |