Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
82dedbf6
H
hub
项目概览
github
/
hub
12 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
82dedbf6
编写于
4月 07, 2014
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Slurp `--noop` during parsing of args
上级
94349d47
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
15 deletion
+37
-15
commands/args.go
commands/args.go
+30
-4
commands/args_test.go
commands/args_test.go
+7
-1
commands/runner.go
commands/runner.go
+0
-10
未找到文件。
commands/args.go
浏览文件 @
82dedbf6
...
...
@@ -2,8 +2,9 @@ package commands
import
(
"fmt"
"github.com/github/hub/cmd"
"strings"
"github.com/github/hub/cmd"
)
type
Args
struct
{
...
...
@@ -131,8 +132,14 @@ func (a *Args) AppendParams(params ...string) {
}
func
NewArgs
(
args
[]
string
)
*
Args
{
var
command
string
var
params
[]
string
var
(
command
string
params
[]
string
noop
bool
)
args
,
noop
=
slurpGlobalFlags
(
args
)
if
len
(
args
)
==
0
{
params
=
[]
string
{}
}
else
{
...
...
@@ -140,7 +147,26 @@ func NewArgs(args []string) *Args {
params
=
args
[
1
:
]
}
return
&
Args
{
Executable
:
"git"
,
Command
:
command
,
Params
:
params
,
beforeChain
:
make
([]
*
cmd
.
Cmd
,
0
),
afterChain
:
make
([]
*
cmd
.
Cmd
,
0
)}
return
&
Args
{
Executable
:
"git"
,
Command
:
command
,
Params
:
params
,
Noop
:
noop
,
beforeChain
:
make
([]
*
cmd
.
Cmd
,
0
),
afterChain
:
make
([]
*
cmd
.
Cmd
,
0
),
}
}
func
slurpGlobalFlags
(
args
[]
string
)
(
aa
[]
string
,
noop
bool
)
{
aa
=
args
for
i
,
arg
:=
range
args
{
if
arg
==
"--noop"
{
noop
=
true
aa
,
_
=
removeItem
(
args
,
i
)
}
}
return
}
func
removeItem
(
slice
[]
string
,
index
int
)
(
newSlice
[]
string
,
item
string
)
{
...
...
commands/args_test.go
浏览文件 @
82dedbf6
package
commands
import
(
"github.com/bmizerany/assert"
"testing"
"github.com/bmizerany/assert"
)
func
TestNewArgs
(
t
*
testing
.
T
)
{
...
...
@@ -17,6 +18,11 @@ func TestNewArgs(t *testing.T) {
args
=
NewArgs
([]
string
{
"command"
,
"args"
})
assert
.
Equal
(
t
,
"command"
,
args
.
Command
)
assert
.
Equal
(
t
,
1
,
args
.
ParamsSize
())
args
=
NewArgs
([]
string
{
"--noop"
,
"command"
,
"args"
})
assert
.
Equal
(
t
,
"command"
,
args
.
Command
)
assert
.
Equal
(
t
,
1
,
args
.
ParamsSize
())
assert
.
T
(
t
,
args
.
Noop
)
}
func
TestArgs_Words
(
t
*
testing
.
T
)
{
...
...
commands/runner.go
浏览文件 @
82dedbf6
...
...
@@ -70,7 +70,6 @@ func (r *Runner) Execute() ExecError {
utils
.
Check
(
err
)
expandAlias
(
args
)
slurpGlobalFlags
(
args
)
cmd
:=
r
.
Lookup
(
args
.
Command
)
if
cmd
!=
nil
&&
cmd
.
Runnable
()
{
...
...
@@ -100,15 +99,6 @@ func (r *Runner) Call(cmd *Command, args *Args) ExecError {
return
newExecError
(
err
)
}
func
slurpGlobalFlags
(
args
*
Args
)
{
for
i
,
p
:=
range
args
.
Params
{
if
p
==
"--noop"
{
args
.
Noop
=
true
args
.
RemoveParam
(
i
)
}
}
}
func
printCommands
(
cmds
[]
*
cmd
.
Cmd
)
{
for
_
,
c
:=
range
cmds
{
fmt
.
Println
(
c
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录