Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
28306a49
提交
28306a49
authored
11月 12, 2014
作者:
Matt Bell
提交者:
Juan Batiz-Benet
11月 14, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands/cli,http: Properly preserve argument value count when checking argument validity
上级
b4735eb1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
24 行删除
+20
-24
parse.go
commands/cli/parse.go
+9
-12
parse.go
commands/http/parse.go
+11
-12
没有找到文件。
commands/cli/parse.go
浏览文件 @
28306a49
...
...
@@ -109,8 +109,6 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
}
func
parseArgs
(
stringArgs
[]
string
,
cmd
*
cmds
.
Command
)
([]
interface
{},
error
)
{
args
:=
make
([]
interface
{},
0
)
// count required argument definitions
lenRequired
:=
0
for
_
,
argDef
:=
range
cmd
.
Arguments
{
...
...
@@ -119,6 +117,8 @@ func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) {
}
}
args
:=
make
([]
interface
{},
len
(
stringArgs
))
valueIndex
:=
0
// the index of the current stringArgs value
for
_
,
argDef
:=
range
cmd
.
Arguments
{
// skip optional argument definitions if there aren't sufficient remaining values
...
...
@@ -134,39 +134,36 @@ func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) {
if
argDef
.
Variadic
{
for
_
,
arg
:=
range
stringArgs
[
valueIndex
:
]
{
var
err
error
args
,
err
=
appendArg
(
args
,
argDef
,
arg
)
value
,
err
:=
argValue
(
argDef
,
arg
)
if
err
!=
nil
{
return
nil
,
err
}
args
[
valueIndex
]
=
value
valueIndex
++
}
}
else
{
var
err
error
args
,
err
=
appendArg
(
args
,
argDef
,
stringArgs
[
valueIndex
])
value
,
err
:=
argValue
(
argDef
,
stringArgs
[
valueIndex
])
if
err
!=
nil
{
return
nil
,
err
}
args
[
valueIndex
]
=
value
valueIndex
++
}
}
if
len
(
stringArgs
)
-
valueIndex
>
0
{
args
=
append
(
args
,
make
([]
interface
{},
len
(
stringArgs
)
-
valueIndex
))
}
return
args
,
nil
}
func
a
ppendArg
(
args
[]
interface
{},
argDef
cmds
.
Argument
,
value
string
)
([]
interface
{},
error
)
{
func
a
rgValue
(
argDef
cmds
.
Argument
,
value
string
)
(
interface
{},
error
)
{
if
argDef
.
Type
==
cmds
.
ArgString
{
return
append
(
args
,
value
)
,
nil
return
value
,
nil
}
else
{
in
,
err
:=
os
.
Open
(
value
)
// FIXME(btc) must close file. fix before merge
if
err
!=
nil
{
return
nil
,
err
}
return
append
(
args
,
in
)
,
nil
return
in
,
nil
}
}
commands/http/parse.go
浏览文件 @
28306a49
...
...
@@ -39,8 +39,6 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
opts
,
stringArgs2
:=
parseOptions
(
r
)
stringArgs
=
append
(
stringArgs
,
stringArgs2
...
)
args
:=
make
([]
interface
{},
0
)
// count required argument definitions
numRequired
:=
0
for
_
,
argDef
:=
range
cmd
.
Arguments
{
...
...
@@ -52,13 +50,16 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
// count the number of provided argument values
valCount
:=
len
(
stringArgs
)
// TODO: add total number of parts in request body (instead of just 1 if body is present)
if
r
.
Body
!=
nil
{
if
r
.
Body
!=
nil
&&
r
.
ContentLength
!=
0
{
valCount
+=
1
}
args
:=
make
([]
interface
{},
valCount
)
valIndex
:=
0
for
_
,
argDef
:=
range
cmd
.
Arguments
{
// skip optional argument definitions if there aren't sufficient remaining values
if
valCount
<=
numRequired
&&
!
argDef
.
Required
{
if
valCount
-
valIndex
<=
numRequired
&&
!
argDef
.
Required
{
continue
}
else
if
argDef
.
Required
{
numRequired
--
...
...
@@ -67,14 +68,15 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
if
argDef
.
Type
==
cmds
.
ArgString
{
if
argDef
.
Variadic
{
for
_
,
s
:=
range
stringArgs
{
args
=
append
(
args
,
s
)
args
[
valIndex
]
=
s
valIndex
++
}
valCount
-=
len
(
stringArgs
)
}
else
if
len
(
stringArgs
)
>
0
{
args
=
append
(
args
,
stringArgs
[
0
])
args
[
valIndex
]
=
stringArgs
[
0
]
stringArgs
=
stringArgs
[
1
:
]
val
Count
--
val
Index
++
}
else
{
break
...
...
@@ -82,14 +84,11 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
}
else
{
// TODO: create multipart streams for file args
args
=
append
(
args
,
r
.
Body
)
args
[
valIndex
]
=
r
.
Body
valIndex
++
}
}
if
valCount
-
1
>
0
{
args
=
append
(
args
,
make
([]
interface
{},
valCount
-
1
))
}
optDefs
,
err
:=
root
.
GetOptions
(
path
)
if
err
!=
nil
{
return
nil
,
err
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论