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

Make `lookupCommand` a local method to `Command`

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