提交 0bbfad69 编写于 作者: J Jingwen Owen Ou

Make `lookupCommand` a local method to `Command`

上级 546363d5
...@@ -30,7 +30,7 @@ type Command struct { ...@@ -30,7 +30,7 @@ type Command struct {
} }
func (c *Command) Call(args *Args) (err error) { func (c *Command) Call(args *Args) (err error) {
runCommand, err := lookupCommand(c, args) runCommand, err := c.lookupSubCommand(args)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
...@@ -113,7 +113,7 @@ func (c *Command) List() bool { ...@@ -113,7 +113,7 @@ func (c *Command) List() bool {
return c.Short != "" return c.Short != ""
} }
func lookupCommand(c *Command, args *Args) (runCommand *Command, err error) { func (c *Command) lookupSubCommand(args *Args) (runCommand *Command, err error) {
if len(c.subCommands) > 0 && args.HasSubcommand() { if len(c.subCommands) > 0 && args.HasSubcommand() {
subCommandName := args.FirstParam() subCommandName := args.FirstParam()
if subCommand, ok := c.subCommands[subCommandName]; ok { if subCommand, ok := c.subCommands[subCommandName]; ok {
......
package commands package commands
import ( import (
"github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert"
"testing" "testing"
"github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert"
) )
func TestCommandUseSelf(t *testing.T) { func TestCommandUseSelf(t *testing.T) {
...@@ -10,7 +11,7 @@ func TestCommandUseSelf(t *testing.T) { ...@@ -10,7 +11,7 @@ func TestCommandUseSelf(t *testing.T) {
args := NewArgs([]string{"foo"}) args := NewArgs([]string{"foo"})
run, err := lookupCommand(c, args) run, err := c.lookupSubCommand(args)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, c, run) assert.Equal(t, c, run)
...@@ -23,7 +24,7 @@ func TestCommandUseSubcommand(t *testing.T) { ...@@ -23,7 +24,7 @@ func TestCommandUseSubcommand(t *testing.T) {
args := NewArgs([]string{"foo", "bar"}) args := NewArgs([]string{"foo", "bar"})
run, err := lookupCommand(c, args) run, err := c.lookupSubCommand(args)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, s, run) assert.Equal(t, s, run)
...@@ -36,7 +37,7 @@ func TestCommandUseErrorWhenMissingSubcommand(t *testing.T) { ...@@ -36,7 +37,7 @@ func TestCommandUseErrorWhenMissingSubcommand(t *testing.T) {
args := NewArgs([]string{"foo", "baz"}) args := NewArgs([]string{"foo", "baz"})
_, err := lookupCommand(c, args) _, err := c.lookupSubCommand(args)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
} }
...@@ -46,7 +47,7 @@ func TestArgsForCommand(t *testing.T) { ...@@ -46,7 +47,7 @@ func TestArgsForCommand(t *testing.T) {
args := NewArgs([]string{"foo", "bar", "baz"}) args := NewArgs([]string{"foo", "bar", "baz"})
lookupCommand(c, args) c.lookupSubCommand(args)
assert.Equal(t, 2, len(args.Params)) assert.Equal(t, 2, len(args.Params))
} }
...@@ -58,7 +59,7 @@ func TestArgsForSubCommand(t *testing.T) { ...@@ -58,7 +59,7 @@ func TestArgsForSubCommand(t *testing.T) {
args := NewArgs([]string{"foo", "bar", "baz"}) args := NewArgs([]string{"foo", "bar", "baz"})
lookupCommand(c, args) c.lookupSubCommand(args)
assert.Equal(t, 1, len(args.Params)) assert.Equal(t, 1, len(args.Params))
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册