Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
1c8d73f9
提交
1c8d73f9
authored
11月 16, 2014
作者:
Matt Bell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands: Added Request#Files()
上级
fdb71eb5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
21 行删除
+11
-21
request.go
commands/request.go
+11
-21
没有找到文件。
commands/request.go
浏览文件 @
1c8d73f9
...
@@ -3,7 +3,6 @@ package commands
...
@@ -3,7 +3,6 @@ package commands
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
"reflect"
"reflect"
"strconv"
"strconv"
...
@@ -62,13 +61,8 @@ type Request interface {
...
@@ -62,13 +61,8 @@ type Request interface {
Option
(
name
string
)
*
OptionValue
Option
(
name
string
)
*
OptionValue
Options
()
optMap
Options
()
optMap
SetOption
(
name
string
,
val
interface
{})
SetOption
(
name
string
,
val
interface
{})
Arguments
()
[]
interface
{}
// Arguments() returns user provided arguments as declared on the Command.
Files
()
File
//
// NB: `io.Reader`s returned by Arguments() are owned by the library.
// Readers are not guaranteed to remain open after the Command's Run
// function returns.
Arguments
()
[]
interface
{}
// TODO: make argument value type instead of using interface{}
Context
()
*
Context
Context
()
*
Context
SetContext
(
Context
)
SetContext
(
Context
)
Command
()
*
Command
Command
()
*
Command
...
@@ -81,6 +75,7 @@ type request struct {
...
@@ -81,6 +75,7 @@ type request struct {
path
[]
string
path
[]
string
options
optMap
options
optMap
arguments
[]
interface
{}
arguments
[]
interface
{}
files
File
cmd
*
Command
cmd
*
Command
ctx
Context
ctx
Context
optionDefs
map
[
string
]
Option
optionDefs
map
[
string
]
Option
...
@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
...
@@ -152,6 +147,10 @@ func (r *request) Arguments() []interface{} {
return
r
.
arguments
return
r
.
arguments
}
}
func
(
r
*
request
)
Files
()
File
{
return
r
.
files
}
func
(
r
*
request
)
Context
()
*
Context
{
func
(
r
*
request
)
Context
()
*
Context
{
return
&
r
.
ctx
return
&
r
.
ctx
}
}
...
@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
...
@@ -165,16 +164,7 @@ func (r *request) Command() *Command {
}
}
func
(
r
*
request
)
Cleanup
()
error
{
func
(
r
*
request
)
Cleanup
()
error
{
for
_
,
arg
:=
range
r
.
arguments
{
// TODO
closer
,
ok
:=
arg
.
(
io
.
Closer
)
if
ok
{
err
:=
closer
.
Close
()
if
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
}
}
...
@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
...
@@ -253,12 +243,12 @@ func (r *request) ConvertOptions() error {
// NewEmptyRequest initializes an empty request
// NewEmptyRequest initializes an empty request
func
NewEmptyRequest
()
(
Request
,
error
)
{
func
NewEmptyRequest
()
(
Request
,
error
)
{
return
NewRequest
(
nil
,
nil
,
nil
,
nil
,
nil
)
return
NewRequest
(
nil
,
nil
,
nil
,
nil
,
nil
,
nil
)
}
}
// NewRequest returns a request initialized with given arguments
// NewRequest returns a request initialized with given arguments
// An non-nil error will be returned if the provided option values are invalid
// An non-nil error will be returned if the provided option values are invalid
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{},
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
func
NewRequest
(
path
[]
string
,
opts
optMap
,
args
[]
interface
{},
file
File
,
cmd
*
Command
,
optDefs
map
[
string
]
Option
)
(
Request
,
error
)
{
if
path
==
nil
{
if
path
==
nil
{
path
=
make
([]
string
,
0
)
path
=
make
([]
string
,
0
)
}
}
...
@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
...
@@ -272,7 +262,7 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
optDefs
=
make
(
map
[
string
]
Option
)
optDefs
=
make
(
map
[
string
]
Option
)
}
}
req
:=
&
request
{
path
,
opts
,
args
,
cmd
,
Context
{},
optDefs
}
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
Context
{},
optDefs
}
err
:=
req
.
ConvertOptions
()
err
:=
req
.
ConvertOptions
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论