Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
1f5aa5d6
提交
1f5aa5d6
authored
3月 20, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #951 from jbenet/feat/lsHeaders
Feat/ls headers
上级
c0f74b92
07008042
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
43 行增加
和
6 行删除
+43
-6
ls.go
core/commands/ls.go
+18
-5
t0045-ls.sh
test/sharness/t0045-ls.sh
+25
-1
没有找到文件。
core/commands/ls.go
浏览文件 @
1f5aa5d6
...
...
@@ -42,6 +42,9 @@ it contains, with the following format:
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"ipfs-path"
,
true
,
true
,
"The path to the IPFS object(s) to list links from"
)
.
EnableStdin
(),
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"headers"
,
""
,
"Print table headers (Hash, Name, Size)"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
node
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
...
...
@@ -49,6 +52,12 @@ it contains, with the following format:
return
}
// get options early -> exit early in case of error
if
_
,
_
,
err
:=
req
.
Option
(
"headers"
)
.
Bool
();
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
paths
:=
req
.
Arguments
()
dagnodes
:=
make
([]
*
merkledag
.
Node
,
0
)
...
...
@@ -91,21 +100,25 @@ it contains, with the following format:
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
output
:=
res
.
Output
()
.
(
*
LsOutput
)
.
Objects
headers
,
_
,
_
:=
res
.
Request
()
.
Option
(
"headers"
)
.
Bool
()
output
:=
res
.
Output
()
.
(
*
LsOutput
)
var
buf
bytes
.
Buffer
w
:=
tabwriter
.
NewWriter
(
&
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
object
:=
range
output
{
if
len
(
output
)
>
1
{
for
_
,
object
:=
range
output
.
Objects
{
if
len
(
output
.
Objects
)
>
1
{
fmt
.
Fprintf
(
w
,
"%s:
\n
"
,
object
.
Hash
)
}
fmt
.
Fprintln
(
w
,
"Hash
\t
Size
\t
Name
\t
"
)
if
headers
{
fmt
.
Fprintln
(
w
,
"Hash
\t
Size
\t
Name
\t
"
)
}
for
_
,
link
:=
range
object
.
Links
{
if
link
.
Type
==
unixfspb
.
Data_Directory
{
link
.
Name
+=
"/"
}
fmt
.
Fprintf
(
w
,
"%s
\t
%v
\t
%s
\t\n
"
,
link
.
Hash
,
link
.
Size
,
link
.
Name
)
}
if
len
(
output
)
>
1
{
if
len
(
output
.
Objects
)
>
1
{
fmt
.
Fprintln
(
w
)
}
}
...
...
test/sharness/t0045-ls.sh
浏览文件 @
1f5aa5d6
...
...
@@ -43,6 +43,30 @@ test_expect_success "'ipfs ls <three dir hashes>' succeeds" '
test_expect_success
"'ipfs ls <three dir hashes>' output looks good"
'
cat <<-\EOF >expected_ls &&
QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj:
QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss 246 d1/
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy 1143 d2/
QmeomffUNfmQy76CQGy9NdmqEnnHU9soCexBnGU3ezPHVH 13 f1
QmNtocSs7MoDkJMc1RkyisCSKvLadujPsfJfSdJ3e1eA1M 13 f2
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy:
QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd 1035 1024
QmaRGe7bVmVaLmxbrMiVNXqW4pRNNp3xq7hFtyRKA3mtJL 14 a
QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss:
QmQNd6ubRXaNG6Prov8o6vk3bn6eWsj9FxLGrAVDUAGkGe 139 128
QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN 14 a
EOF
test_cmp expected_ls actual_ls
'
test_expect_success
"'ipfs ls --headers <three dir hashes>' succeeds"
'
ipfs ls --headers QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls_headers
'
test_expect_success
"'ipfs ls --headers <three dir hashes>' output looks good"
'
cat <<-\EOF >expected_ls_headers &&
QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj:
Hash Size Name
QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss 246 d1/
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy 1143 d2/
...
...
@@ -60,7 +84,7 @@ test_expect_success "'ipfs ls <three dir hashes>' output looks good" '
QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN 14 a
EOF
test_cmp expected_ls
actual_l
s
test_cmp expected_ls
_headers actual_ls_header
s
'
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论