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
edb8eeae
Commit
edb8eeae
authored
Nov 18, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands: Created a general key list output type and plaintext marshaler
parent
961e4504
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
core/commands/refs.go
core/commands/refs.go
+15
-13
No files found.
core/commands/refs.go
View file @
edb8eeae
...
@@ -2,6 +2,7 @@ package commands
...
@@ -2,6 +2,7 @@ package commands
import
(
import
(
"fmt"
"fmt"
"strings"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
cmds
"github.com/jbenet/go-ipfs/commands"
cmds
"github.com/jbenet/go-ipfs/commands"
...
@@ -10,8 +11,16 @@ import (
...
@@ -10,8 +11,16 @@ import (
u
"github.com/jbenet/go-ipfs/util"
u
"github.com/jbenet/go-ipfs/util"
)
)
type
RefsOutput
struct
{
// KeyList is a general type for outputting lists of keys
Refs
[]
string
type
KeyList
struct
{
Keys
[]
string
}
// KeyListTextMarshaler outputs a KeyList as plaintext, one key per line
func
KeyListTextMarshaler
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
output
:=
res
.
Output
()
.
(
*
KeyList
)
s
:=
strings
.
Join
(
output
.
Keys
,
"
\n
"
)
return
[]
byte
(
s
),
nil
}
}
var
refsCmd
=
&
cmds
.
Command
{
var
refsCmd
=
&
cmds
.
Command
{
...
@@ -58,20 +67,13 @@ Note: list all refs recursively with -r.
...
@@ -58,20 +67,13 @@ Note: list all refs recursively with -r.
return
getRefs
(
n
,
req
.
Arguments
(),
unique
,
recursive
)
return
getRefs
(
n
,
req
.
Arguments
(),
unique
,
recursive
)
},
},
Type
:
&
RefsOutpu
t
{},
Type
:
&
KeyLis
t
{},
Marshalers
:
cmds
.
MarshalerMap
{
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
cmds
.
Text
:
KeyListTextMarshaler
,
output
:=
res
.
Output
()
.
(
*
RefsOutput
)
s
:=
""
for
_
,
ref
:=
range
output
.
Refs
{
s
+=
fmt
.
Sprintln
(
ref
)
}
return
[]
byte
(
s
),
nil
},
},
},
}
}
func
getRefs
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
unique
,
recursive
bool
)
(
*
RefsOutpu
t
,
error
)
{
func
getRefs
(
n
*
core
.
IpfsNode
,
paths
[]
string
,
unique
,
recursive
bool
)
(
*
KeyLis
t
,
error
)
{
var
refsSeen
map
[
u
.
Key
]
bool
var
refsSeen
map
[
u
.
Key
]
bool
if
unique
{
if
unique
{
refsSeen
=
make
(
map
[
u
.
Key
]
bool
)
refsSeen
=
make
(
map
[
u
.
Key
]
bool
)
...
@@ -91,7 +93,7 @@ func getRefs(n *core.IpfsNode, paths []string, unique, recursive bool) (*RefsOut
...
@@ -91,7 +93,7 @@ func getRefs(n *core.IpfsNode, paths []string, unique, recursive bool) (*RefsOut
}
}
}
}
return
&
RefsOutpu
t
{
refs
},
nil
return
&
KeyLis
t
{
refs
},
nil
}
}
func
addRefs
(
n
*
core
.
IpfsNode
,
object
*
dag
.
Node
,
refs
[]
string
,
refsSeen
map
[
u
.
Key
]
bool
,
recursive
bool
)
([]
string
,
error
)
{
func
addRefs
(
n
*
core
.
IpfsNode
,
object
*
dag
.
Node
,
refs
[]
string
,
refsSeen
map
[
u
.
Key
]
bool
,
recursive
bool
)
([]
string
,
error
)
{
...
...
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