Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
f2271356
Commit
f2271356
authored
Oct 30, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands2: Added 'ls' command
parent
e01f1ba8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
core/commands2/ls.go
core/commands2/ls.go
+60
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/ls.go
0 → 100644
View file @
f2271356
package
commands
import
(
"fmt"
cmds
"github.com/jbenet/go-ipfs/commands"
)
type
Link
struct
{
Name
,
Hash
string
Size
uint64
}
var
ls
=
&
cmds
.
Command
{
Help
:
"TODO"
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
node
:=
req
.
Context
()
.
Node
output
:=
make
(
map
[
string
][]
Link
,
len
(
req
.
Arguments
()))
for
_
,
path
:=
range
req
.
Arguments
()
{
dagnode
,
err
:=
node
.
Resolver
.
ResolvePath
(
path
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
[
path
]
=
make
([]
Link
,
len
(
dagnode
.
Links
))
for
i
,
link
:=
range
dagnode
.
Links
{
output
[
path
][
i
]
=
Link
{
Name
:
link
.
Name
,
Hash
:
link
.
Hash
.
B58String
(),
Size
:
link
.
Size
,
}
}
}
res
.
SetValue
(
output
)
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
s
:=
""
output
:=
res
.
Value
()
.
(
*
map
[
string
][]
Link
)
for
path
,
links
:=
range
*
output
{
if
len
(
*
output
)
>
1
{
s
+=
fmt
.
Sprintf
(
"%s:
\n
"
,
path
)
}
for
_
,
link
:=
range
links
{
s
+=
fmt
.
Sprintf
(
"-> %s %s (%v bytes)
\n
"
,
link
.
Name
,
link
.
Hash
,
link
.
Size
)
}
if
len
(
*
output
)
>
1
{
s
+=
"
\n
"
}
}
return
s
,
nil
},
Type
:
&
map
[
string
][]
Link
{},
}
core/commands2/root.go
View file @
f2271356
...
@@ -52,6 +52,7 @@ Use "ipfs help <command>" for more information about a command.
...
@@ -52,6 +52,7 @@ Use "ipfs help <command>" for more information about a command.
`
,
`
,
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"cat"
:
cat
,
"cat"
:
cat
,
"ls"
:
ls
,
// test subcommands
// test subcommands
// TODO: remove these when we don't need them anymore
// TODO: remove these when we don't need them anymore
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment