Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
96433cc6
提交
96433cc6
authored
7月 07, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
starting to rework stdin handling
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
5d1b28e2
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
71 行增加
和
24 行删除
+71
-24
argument.go
commands/argument.go
+0
-3
parse.go
commands/cli/parse.go
+10
-4
command.go
commands/command.go
+4
-0
pin.go
core/commands/pin.go
+56
-16
t0022-init-default.sh
test/sharness/t0022-init-default.sh
+1
-1
没有找到文件。
commands/argument.go
浏览文件 @
96433cc6
...
...
@@ -42,9 +42,6 @@ func FileArg(name string, required, variadic bool, description string) Argument
// (`FileArg("file", ArgRequired, ArgStdin, ArgRecursive)`)
func
(
a
Argument
)
EnableStdin
()
Argument
{
if
a
.
Type
==
ArgString
{
panic
(
"Only FileArgs can be read from Stdin"
)
}
a
.
SupportsStdin
=
true
return
a
}
...
...
commands/cli/parse.go
浏览文件 @
96433cc6
...
...
@@ -276,6 +276,7 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
fileArgs
:=
make
(
map
[
string
]
files
.
File
)
argDefIndex
:=
0
// the index of the current argument definition
for
i
:=
0
;
i
<
numInputs
;
i
++
{
argDef
:=
getArgDef
(
argDefIndex
,
argDefs
)
...
...
@@ -289,14 +290,19 @@ func parseArgs(inputs []string, stdin *os.File, argDefs []cmds.Argument, recursi
}
fillingVariadic
:=
argDefIndex
+
1
>
len
(
argDefs
)
if
argDef
.
Type
==
cmds
.
ArgString
{
switch
argDef
.
Type
{
case
cmds
.
ArgString
:
if
len
(
inputs
)
>
0
{
stringArgs
,
inputs
=
append
(
stringArgs
,
inputs
[
0
]),
inputs
[
1
:
]
}
else
{
break
if
stdin
!=
nil
&&
argDef
.
SupportsStdin
&&
!
fillingVariadic
{
if
err
:=
printReadInfo
(
stdin
,
msgStdinInfo
);
err
==
nil
{
fileArgs
[
stdin
.
Name
()]
=
files
.
NewReaderFile
(
""
,
stdin
.
Name
(),
stdin
,
nil
)
stdin
=
nil
}
}
}
}
else
if
argDef
.
Type
==
cmds
.
ArgFile
{
case
cmds
.
ArgFile
:
if
len
(
inputs
)
>
0
{
// treat stringArg values as file paths
fpath
:=
inputs
[
0
]
...
...
commands/command.go
浏览文件 @
96433cc6
...
...
@@ -281,6 +281,10 @@ func (c *Command) ProcessHelp() {
// checkArgValue returns an error if a given arg value is not valid for the
// given Argument
func
checkArgValue
(
v
string
,
found
bool
,
def
Argument
)
error
{
if
def
.
Variadic
&&
def
.
SupportsStdin
{
return
nil
}
if
!
found
&&
def
.
Required
{
return
fmt
.
Errorf
(
"Argument '%s' is required"
,
def
.
Name
)
}
...
...
core/commands/pin.go
浏览文件 @
96433cc6
package
commands
import
(
"bufio"
"bytes"
"fmt"
"io"
...
...
@@ -39,7 +40,7 @@ var addPinCmd = &cmds.Command{
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"ipfs-path"
,
true
,
true
,
"Path to object(s) to be pinned."
),
cmds
.
StringArg
(
"ipfs-path"
,
true
,
true
,
"Path to object(s) to be pinned."
)
.
EnableStdin
()
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"recursive"
,
"r"
,
"Recursively pin the object linked to by the specified object(s)."
)
.
Default
(
true
),
...
...
@@ -61,21 +62,40 @@ var addPinCmd = &cmds.Command{
return
}
added
,
err
:=
corerepo
.
Pin
(
n
,
req
.
Context
(),
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
len
(
req
.
Arguments
())
>
0
{
added
,
err
:=
corerepo
.
Pin
(
n
,
req
.
Context
(),
req
.
Arguments
(),
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
&
PinOutput
{
added
})
res
.
SetOutput
(
&
PinOutput
{
added
})
}
else
{
fi
,
err
:=
req
.
Files
()
.
NextFile
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
out
:=
make
(
chan
interface
{})
go
func
(
ctx
context
.
Context
)
{
defer
close
(
out
)
scan
:=
bufio
.
NewScanner
(
fi
)
for
scan
.
Scan
()
{
added
,
err
:=
corerepo
.
Pin
(
n
,
ctx
,
[]
string
{
scan
.
Text
()},
recursive
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
out
<-
&
PinOutput
{
added
}
}
}(
req
.
Context
())
res
.
SetOutput
((
<-
chan
interface
{})(
out
))
}
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
added
,
ok
:=
res
.
Output
()
.
(
*
PinOutput
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
var
pintype
string
rec
,
found
,
_
:=
res
.
Request
()
.
Option
(
"recursive"
)
.
Bool
()
if
rec
||
!
found
{
...
...
@@ -84,11 +104,31 @@ var addPinCmd = &cmds.Command{
pintype
=
"directly"
}
buf
:=
new
(
bytes
.
Buffer
)
for
_
,
k
:=
range
added
.
Pins
{
fmt
.
Fprintf
(
buf
,
"pinned %s %s
\n
"
,
k
,
pintype
)
marshalPinOutput
:=
func
(
po
*
PinOutput
)
io
.
Reader
{
buf
:=
new
(
bytes
.
Buffer
)
for
_
,
k
:=
range
po
.
Pins
{
fmt
.
Fprintf
(
buf
,
"pinned %s %s
\n
"
,
k
,
pintype
)
}
return
buf
}
switch
out
:=
res
.
Output
()
.
(
type
)
{
case
*
PinOutput
:
return
marshalPinOutput
(
out
),
nil
case
<-
chan
interface
{}
:
marshal
:=
func
(
i
interface
{})
(
io
.
Reader
,
error
)
{
return
marshalPinOutput
(
i
.
(
*
PinOutput
)),
nil
}
return
&
cmds
.
ChannelMarshaler
{
Res
:
res
,
Marshaler
:
marshal
,
Channel
:
out
,
},
nil
default
:
return
nil
,
u
.
ErrCast
()
}
return
buf
,
nil
},
},
}
...
...
test/sharness/t0022-init-default.sh
浏览文件 @
96433cc6
...
...
@@ -48,7 +48,7 @@ test_expect_success "ipfs config output looks good" '
test_cmp expected actual
'
test_launch_ipfs_daemon
test_launch_ipfs_daemon
--offline
test_kill_ipfs_daemon
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论