Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
3fc9bedb
提交
3fc9bedb
authored
1月 22, 2015
作者:
Matt Bell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands: Made Std{in|out|err} accessible in Request/Response
上级
b77d1c21
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
34 行增加
和
9 行删除
+34
-9
request.go
commands/request.go
+9
-1
response.go
commands/response.go
+20
-1
add.go
core/commands/add.go
+4
-5
cat.go
core/commands/cat.go
+1
-2
没有找到文件。
commands/request.go
浏览文件 @
3fc9bedb
...
...
@@ -3,6 +3,8 @@ package commands
import
(
"errors"
"fmt"
"io"
"os"
"reflect"
"strconv"
...
...
@@ -78,6 +80,7 @@ type Request interface {
SetContext
(
Context
)
Command
()
*
Command
Values
()
map
[
string
]
interface
{}
Stdin
()
io
.
Reader
ConvertOptions
()
error
}
...
...
@@ -91,6 +94,7 @@ type request struct {
ctx
Context
optionDefs
map
[
string
]
Option
values
map
[
string
]
interface
{}
stdin
io
.
Reader
}
// Path returns the command path of this request
...
...
@@ -214,6 +218,10 @@ func (r *request) Values() map[string]interface{} {
return
r
.
values
}
func
(
r
*
request
)
Stdin
()
io
.
Reader
{
return
r
.
stdin
}
func
(
r
*
request
)
ConvertOptions
()
error
{
for
k
,
v
:=
range
r
.
options
{
opt
,
ok
:=
r
.
optionDefs
[
k
]
...
...
@@ -282,7 +290,7 @@ func NewRequest(path []string, opts optMap, args []string, file files.File, cmd
ctx
:=
Context
{
Context
:
context
.
TODO
()}
values
:=
make
(
map
[
string
]
interface
{})
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
ctx
,
optDefs
,
values
}
req
:=
&
request
{
path
,
opts
,
args
,
file
,
cmd
,
ctx
,
optDefs
,
values
,
os
.
Stdin
}
err
:=
req
.
ConvertOptions
()
if
err
!=
nil
{
return
nil
,
err
...
...
commands/response.go
浏览文件 @
3fc9bedb
...
...
@@ -6,6 +6,7 @@ import (
"encoding/xml"
"fmt"
"io"
"os"
"strings"
)
...
...
@@ -105,6 +106,10 @@ type Response interface {
// Gets a io.Reader that reads the marshalled output
Reader
()
(
io
.
Reader
,
error
)
// Gets Stdout and Stderr, for writing to console without using SetOutput
Stdout
()
io
.
Writer
Stderr
()
io
.
Writer
}
type
response
struct
{
...
...
@@ -113,6 +118,8 @@ type response struct {
value
interface
{}
out
io
.
Reader
length
uint64
stdout
io
.
Writer
stderr
io
.
Writer
}
func
(
r
*
response
)
Request
()
Request
{
...
...
@@ -206,7 +213,19 @@ func (r *response) Reader() (io.Reader, error) {
return
r
.
out
,
nil
}
func
(
r
*
response
)
Stdout
()
io
.
Writer
{
return
r
.
stdout
}
func
(
r
*
response
)
Stderr
()
io
.
Writer
{
return
r
.
stderr
}
// NewResponse returns a response to match given Request
func
NewResponse
(
req
Request
)
Response
{
return
&
response
{
req
:
req
}
return
&
response
{
req
:
req
,
stdout
:
os
.
Stdout
,
stderr
:
os
.
Stderr
,
}
}
core/commands/add.go
浏览文件 @
3fc9bedb
...
...
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"os"
"path"
"strings"
...
...
@@ -139,7 +138,7 @@ remains to be implemented.
bar
.
Callback
=
func
(
line
string
)
{
terminalWidth
=
len
(
line
)
bar
.
Callback
=
nil
bar
.
Output
=
os
.
Stderr
bar
.
Output
=
res
.
Stderr
()
log
.
Infof
(
"terminal width: %v
\n
"
,
terminalWidth
)
}
bar
.
Update
()
...
...
@@ -153,12 +152,12 @@ remains to be implemented.
if
len
(
output
.
Hash
)
>
0
{
if
showProgressBar
{
// clear progress bar line before we print "added x" output
fmt
.
Fprintf
(
os
.
Stderr
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
fmt
.
Fprintf
(
res
.
Stderr
()
,
"
\r
%s
\r
"
,
strings
.
Repeat
(
" "
,
terminalWidth
))
}
if
quiet
{
fmt
.
Printf
(
"%s
\n
"
,
output
.
Hash
)
fmt
.
Fprintf
(
res
.
Stdout
(),
"%s
\n
"
,
output
.
Hash
)
}
else
{
fmt
.
Printf
(
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
fmt
.
Fprintf
(
res
.
Stdout
(),
"added %s %s
\n
"
,
output
.
Hash
,
output
.
Name
)
}
}
else
{
...
...
core/commands/cat.go
浏览文件 @
3fc9bedb
...
...
@@ -2,7 +2,6 @@ package commands
import
(
"io"
"os"
cmds
"github.com/jbenet/go-ipfs/commands"
core
"github.com/jbenet/go-ipfs/core"
...
...
@@ -51,7 +50,7 @@ it contains.
}
bar
:=
pb
.
New
(
int
(
res
.
Length
()))
.
SetUnits
(
pb
.
U_BYTES
)
bar
.
Output
=
os
.
Stderr
bar
.
Output
=
res
.
Stderr
()
bar
.
Start
()
reader
:=
bar
.
NewProxyReader
(
res
.
Output
()
.
(
io
.
Reader
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论