Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f8eefba0
提交
f8eefba0
authored
2月 17, 2016
作者:
Jeromy Johnson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2354 from ipfs/fix/stdin-arg-parse
fix panic in cli arg parsing
上级
ef7b3735
dbf0185a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
12 行删除
+20
-12
parse.go
commands/cli/parse.go
+8
-1
parse_test.go
commands/cli/parse_test.go
+11
-10
dht.go
core/commands/dht.go
+1
-1
没有找到文件。
commands/cli/parse.go
浏览文件 @
f8eefba0
...
...
@@ -297,10 +297,17 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
var
err
error
if
argDef
.
Type
==
cmds
.
ArgString
{
if
stdin
==
nil
||
!
argDef
.
SupportsStdin
{
if
stdin
==
nil
{
// add string values
stringArgs
,
inputs
=
appendString
(
stringArgs
,
inputs
)
}
else
if
!
argDef
.
SupportsStdin
{
if
len
(
inputs
)
==
0
{
// failure case, we have stdin, but our current
// argument doesnt want stdin
break
}
stringArgs
,
inputs
=
appendString
(
stringArgs
,
inputs
)
}
else
{
if
len
(
inputs
)
>
0
{
// don't use stdin if we have inputs
...
...
commands/cli/parse_test.go
浏览文件 @
f8eefba0
...
...
@@ -212,7 +212,7 @@ func TestArgumentParsing(t *testing.T) {
}
}
testFail
:=
func
(
cmd
words
,
msg
string
)
{
testFail
:=
func
(
cmd
words
,
fi
*
os
.
File
,
msg
string
)
{
_
,
_
,
_
,
err
:=
Parse
(
cmd
,
nil
,
rootCmd
)
if
err
==
nil
{
t
.
Errorf
(
"Should have failed: %v"
,
msg
)
...
...
@@ -220,18 +220,18 @@ func TestArgumentParsing(t *testing.T) {
}
test
([]
string
{
"noarg"
},
nil
,
[]
string
{})
testFail
([]
string
{
"noarg"
,
"value!"
},
"provided an arg, but command didn't define any"
)
testFail
([]
string
{
"noarg"
,
"value!"
},
nil
,
"provided an arg, but command didn't define any"
)
test
([]
string
{
"onearg"
,
"value!"
},
nil
,
[]
string
{
"value!"
})
testFail
([]
string
{
"onearg"
},
"didn't provide any args, arg is required"
)
testFail
([]
string
{
"onearg"
},
nil
,
"didn't provide any args, arg is required"
)
test
([]
string
{
"twoargs"
,
"value1"
,
"value2"
},
nil
,
[]
string
{
"value1"
,
"value2"
})
testFail
([]
string
{
"twoargs"
,
"value!"
},
"only provided 1 arg, needs 2"
)
testFail
([]
string
{
"twoargs"
},
"didn't provide any args, 2 required"
)
testFail
([]
string
{
"twoargs"
,
"value!"
},
nil
,
"only provided 1 arg, needs 2"
)
testFail
([]
string
{
"twoargs"
},
nil
,
"didn't provide any args, 2 required"
)
test
([]
string
{
"variadic"
,
"value!"
},
nil
,
[]
string
{
"value!"
})
test
([]
string
{
"variadic"
,
"value1"
,
"value2"
,
"value3"
},
nil
,
[]
string
{
"value1"
,
"value2"
,
"value3"
})
testFail
([]
string
{
"variadic"
},
"didn't provide any args, 1 required"
)
testFail
([]
string
{
"variadic"
},
nil
,
"didn't provide any args, 1 required"
)
test
([]
string
{
"optional"
,
"value!"
},
nil
,
[]
string
{
"value!"
})
test
([]
string
{
"optional"
},
nil
,
[]
string
{})
...
...
@@ -239,14 +239,14 @@ func TestArgumentParsing(t *testing.T) {
test
([]
string
{
"optionalsecond"
,
"value!"
},
nil
,
[]
string
{
"value!"
})
test
([]
string
{
"optionalsecond"
,
"value1"
,
"value2"
},
nil
,
[]
string
{
"value1"
,
"value2"
})
testFail
([]
string
{
"optionalsecond"
},
"didn't provide any args, 1 required"
)
testFail
([]
string
{
"optionalsecond"
,
"value1"
,
"value2"
,
"value3"
},
"provided too many args, takes 2 maximum"
)
testFail
([]
string
{
"optionalsecond"
},
nil
,
"didn't provide any args, 1 required"
)
testFail
([]
string
{
"optionalsecond"
,
"value1"
,
"value2"
,
"value3"
},
nil
,
"provided too many args, takes 2 maximum"
)
test
([]
string
{
"reversedoptional"
,
"value1"
,
"value2"
},
nil
,
[]
string
{
"value1"
,
"value2"
})
test
([]
string
{
"reversedoptional"
,
"value!"
},
nil
,
[]
string
{
"value!"
})
testFail
([]
string
{
"reversedoptional"
},
"didn't provide any args, 1 required"
)
testFail
([]
string
{
"reversedoptional"
,
"value1"
,
"value2"
,
"value3"
},
"provided too many args, only takes 1"
)
testFail
([]
string
{
"reversedoptional"
},
nil
,
"didn't provide any args, 1 required"
)
testFail
([]
string
{
"reversedoptional"
,
"value1"
,
"value2"
,
"value3"
},
nil
,
"provided too many args, only takes 1"
)
// Use a temp file to simulate stdin
fileToSimulateStdin
:=
func
(
t
*
testing
.
T
,
content
string
)
*
os
.
File
{
...
...
@@ -296,6 +296,7 @@ func TestArgumentParsing(t *testing.T) {
fstdin
=
fileToSimulateStdin
(
t
,
"stdin1"
)
test
([]
string
{
"stdinenablednotvariadic2args"
,
"value1"
},
fstdin
,
[]
string
{
"value1"
,
"stdin1"
})
test
([]
string
{
"stdinenablednotvariadic2args"
,
"value1"
,
"value2"
},
fstdin
,
[]
string
{
"value1"
,
"value2"
})
testFail
([]
string
{
"stdinenablednotvariadic2args"
},
fstdin
,
"cant use stdin for non stdin arg"
)
fstdin
=
fileToSimulateStdin
(
t
,
"stdin1"
)
test
([]
string
{
"noarg"
},
fstdin
,
[]
string
{})
...
...
core/commands/dht.go
浏览文件 @
f8eefba0
...
...
@@ -12,8 +12,8 @@ import (
notif
"github.com/ipfs/go-ipfs/notifications"
path
"github.com/ipfs/go-ipfs/path"
ipdht
"github.com/ipfs/go-ipfs/routing/dht"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
peer
"gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/peer"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
)
var
ErrNotDHT
=
errors
.
New
(
"routing service is not a DHT"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论