Skip to content

Commit

Permalink
Auto merge of #2308 - ota42y:feature/alias_command, r=hsbt
Browse files Browse the repository at this point in the history
Add alias command 'i' for 'install' command

# Description:

In rubygems 2.x, the command that started with `i` was `install` command only.
So we can install gem by following command like [npm](https://docs.npmjs.com/cli/install).
`gem i bundler`

But rubygems 3.x have `info` command.
#2023

So this command doesn't work

```bash
% gem i bundler
ERROR:  While executing gem ... (Gem::CommandLineError)
    Ambiguous command i matches [info, install]
```

The `i` command work well in 2.x and this command is very useful as we install lots of gem.
So it would be nice to set an alias for this command.

______________

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [ ] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
  • Loading branch information
bundlerbot committed Jun 1, 2018
2 parents 3a1f2c3 + 02a1ca9 commit 7f04b8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class Gem::CommandManager
:yank,
]

ALIAS_COMMANDS = {
'i' => 'install'
}

##
# Return the authoritative instance of the command manager.

Expand Down Expand Up @@ -174,6 +178,8 @@ def process_args(args, build_args=nil)
end

def find_command(cmd_name)
cmd_name = find_alias_command cmd_name

possibilities = find_command_possibilities cmd_name

if possibilities.size > 1 then
Expand All @@ -186,6 +192,11 @@ def find_command(cmd_name)
self[possibilities.first]
end

def find_alias_command(cmd_name)
alias_name = ALIAS_COMMANDS[cmd_name]
alias_name ? alias_name : cmd_name
end

def find_command_possibilities(cmd_name)
len = cmd_name.length

Expand Down
6 changes: 6 additions & 0 deletions test/rubygems/test_gem_command_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def test_find_command_ambiguous
e.message
end

def test_find_alias_command
command = @command_manager.find_command 'i'

assert_kind_of Gem::Commands::InstallCommand, command
end

def test_find_command_ambiguous_exact
ins_command = Class.new
Gem::Commands.send :const_set, :InsCommand, ins_command
Expand Down

0 comments on commit 7f04b8a

Please sign in to comment.