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
f1c20b4e
Commit
f1c20b4e
authored
Nov 13, 2014
by
Brian Tiger Chow
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't use the marshaler
License: MIT Signed-off-by:
Brian Tiger Chow
<
brian@perfmode.com
>
parent
35da357d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
48 deletions
+10
-48
cmd/ipfs2/tour.go
cmd/ipfs2/tour.go
+9
-47
cmd/ipfs2/tour_test.go
cmd/ipfs2/tour_test.go
+1
-1
No files found.
cmd/ipfs2/tour.go
View file @
f1c20b4e
...
...
@@ -11,7 +11,6 @@ import (
config
"github.com/jbenet/go-ipfs/config"
internal
"github.com/jbenet/go-ipfs/core/commands2/internal"
tour
"github.com/jbenet/go-ipfs/tour"
"github.com/jbenet/go-ipfs/util"
)
// TODO the parent function now uses tourOutput. Migrate the children to also
...
...
@@ -38,46 +37,6 @@ IPFS very quickly. To start, run:
"restart"
:
cmdIpfsTourRestart
,
},
Run
:
tourRunFunc
,
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
tourTextMarshaler
,
},
Type
:
&
tourOutput
{},
}
// tourOutput is a union type. It either contains a Topic or it contains the
// list of Topics and an Error.
type
tourOutput
struct
{
Last
tour
.
ID
Topic
*
tour
.
Topic
Topics
[]
tour
.
Topic
Error
error
}
func
tourTextMarshaler
(
r
cmds
.
Response
)
([]
byte
,
error
)
{
output
,
ok
:=
r
.
Output
()
.
(
*
tourOutput
)
if
!
ok
{
return
nil
,
util
.
ErrCast
()
}
// can be listing when error
var
buf
bytes
.
Buffer
err
:=
printTourOutput
(
&
buf
,
output
)
if
err
!=
nil
{
return
nil
,
err
}
return
buf
.
Bytes
(),
nil
}
func
printTourOutput
(
w
io
.
Writer
,
output
*
tourOutput
)
error
{
if
output
.
Error
!=
nil
{
fmt
.
Fprintln
(
w
,
"ERROR"
)
fmt
.
Fprintln
(
w
,
output
.
Error
.
Error
())
fmt
.
Fprintln
(
w
,
""
)
fprintTourList
(
w
,
output
.
Last
)
return
nil
// TODO err
}
return
fprintTourShow
(
w
,
output
.
Topic
)
}
func
tourRunFunc
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
...
...
@@ -97,6 +56,8 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
id
=
tour
.
TopicID
(
strs
[
0
])
}
var
w
bytes
.
Buffer
defer
w
.
WriteTo
(
os
.
Stdout
)
t
,
err
:=
tourGet
(
id
)
if
err
!=
nil
{
...
...
@@ -106,15 +67,16 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
// 1) a simple error message
// 2) the full list of topics
output
:=
&
tourOutput
{
Error
:
err
,
Last
:
tour
.
TopicID
(
cfg
.
Tour
.
Last
),
}
fmt
.
Fprintln
(
&
w
,
"ERROR"
)
fmt
.
Fprintln
(
&
w
,
err
)
fmt
.
Fprintln
(
&
w
,
""
)
fprintTourList
(
&
w
,
tour
.
TopicID
(
cfg
.
Tour
.
Last
))
return
output
,
nil
return
nil
,
nil
}
return
&
tourOutput
{
Topic
:
t
},
nil
fprintTourShow
(
&
w
,
t
)
return
nil
,
nil
}
var
cmdIpfsTourNext
=
&
cmds
.
Command
{
...
...
cmd/ipfs2/tour_test.go
View file @
f1c20b4e
...
...
@@ -18,7 +18,7 @@ This is where we test our beautiful command line interfaces
`
,
}
var
buf
bytes
.
Buffer
err
:=
t
ourShow
(
&
buf
,
topic
)
err
:=
fprintT
ourShow
(
&
buf
,
topic
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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