don't use the marshaler
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 13, 2014 at 21:05 UTC
f1c20b4e3a0fb7123bbffeb0a9a847de5aa0ac81
2 files changed
+10
-48
cmd/ipfs2/tour.go
+9
-47
@@ -11,7 +11,6 @@ import (
11
config "github.com/jbenet/go-ipfs/config"
12
internal "github.com/jbenet/go-ipfs/core/commands2/internal"
13
tour "github.com/jbenet/go-ipfs/tour"
14
- "github.com/jbenet/go-ipfs/util"
14
)
15
16
// TODO the parent function now uses tourOutput. Migrate the children to also
@@ -38,46 +37,6 @@ IPFS very quickly. To start, run:
37
"restart": cmdIpfsTourRestart,
38
},
39
Run: tourRunFunc,
41
- Marshalers: cmds.MarshalerMap{
42
- cmds.Text: tourTextMarshaler,
43
- },
44
- Type: &tourOutput{},
45
-}
46
-
47
-// tourOutput is a union type. It either contains a Topic or it contains the
48
-// list of Topics and an Error.
49
-type tourOutput struct {
50
- Last tour.ID
51
-
52
- Topic *tour.Topic
53
-
54
- Topics []tour.Topic
55
- Error error
56
-}
57
-
58
-func tourTextMarshaler(r cmds.Response) ([]byte, error) {
59
- output, ok := r.Output().(*tourOutput)
60
- if !ok {
61
- return nil, util.ErrCast()
62
- }
63
- // can be listing when error
64
- var buf bytes.Buffer
65
- err := printTourOutput(&buf, output)
66
- if err != nil {
67
- return nil, err
68
- }
69
- return buf.Bytes(), nil
70
-}
71
-
72
-func printTourOutput(w io.Writer, output *tourOutput) error {
73
- if output.Error != nil {
74
- fmt.Fprintln(w, "ERROR")
75
- fmt.Fprintln(w, output.Error.Error())
76
- fmt.Fprintln(w, "")
77
- fprintTourList(w, output.Last)
78
- return nil // TODO err
79
- }
80
- return fprintTourShow(w, output.Topic)
40
}
41
42
func tourRunFunc(req cmds.Request) (interface{}, error) {
@@ -97,6 +56,8 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
56
id = tour.TopicID(strs[0])
57
}
58
59
+ var w bytes.Buffer
60
+ defer w.WriteTo(os.Stdout)
61
t, err := tourGet(id)
62
if err != nil {
63
@@ -106,15 +67,16 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
67
// 1) a simple error message
68
// 2) the full list of topics
69
109
- output := &tourOutput{
110
- Error: err,
111
- Last: tour.TopicID(cfg.Tour.Last),
112
- }
70
+ fmt.Fprintln(&w, "ERROR")
71
+ fmt.Fprintln(&w, err)
72
+ fmt.Fprintln(&w, "")
73
+ fprintTourList(&w, tour.TopicID(cfg.Tour.Last))
74
114
- return output, nil
75
+ return nil, nil
76
}
77
117
- return &tourOutput{Topic: t}, nil
78
+ fprintTourShow(&w, t)
79
+ return nil, nil
80
}
81
82
var cmdIpfsTourNext = &cmds.Command{
cmd/ipfs2/tour_test.go
+1
-1
@@ -18,7 +18,7 @@ This is where we test our beautiful command line interfaces
18
`,
19
}
20
var buf bytes.Buffer
21
- err := tourShow(&buf, topic)
21
+ err := fprintTourShow(&buf, topic)
22
if err != nil {
23
t.Fatal(err)
24
}