commands: Replaced 'Formatter' with 'Marshaller'
Matt Bell committed
Nov 3, 2014 at 23:02 UTC
0afd3391a8e630bcb4b0cb80fc157053dbfa0779
6 files changed
+17
-14
core/commands2/add.go
+4
-3
@@ -55,17 +55,18 @@ var addCmd = &cmds.Command{
55
56
res.SetOutput(&AddOutput{added})
57
},
58
- Format: func(res cmds.Response) (string, error) {
58
+ Format: func(res cmds.Response) ([]byte, error) {
59
v := res.Output().(*AddOutput).Added
60
if len(v) == 1 {
61
- return fmt.Sprintf("Added object: %s\n", v[0].Hash), nil
61
+ s := fmt.Sprintf("Added object: %s\n", v[0].Hash)
62
+ return []byte(s), nil
63
}
64
65
s := fmt.Sprintf("Added %v objects:\n", len(v))
66
for _, obj := range v {
67
s += fmt.Sprintf("- %s\n", obj.Hash)
68
}
68
- return s, nil
69
+ return []byte(s), nil
70
},
71
Type: &AddOutput{},
72
}
core/commands2/commands.go
+3
-2
@@ -18,9 +18,10 @@ var commandsCmd = &cmds.Command{
18
root := outputCommand("ipfs", Root)
19
res.SetOutput(&root)
20
},
21
- Format: func(res cmds.Response) (string, error) {
21
+ Format: func(res cmds.Response) ([]byte, error) {
22
v := res.Output().(*Command)
23
- return formatCommand(v, 0), nil
23
+ s := formatCommand(v, 0)
24
+ return []byte(s), nil
25
},
26
Type: &Command{},
27
}
core/commands2/log.go
+1
-1
@@ -23,6 +23,6 @@ var logCmd = &cmds.Command{
23
s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
24
res.SetOutput(&MessageOutput{s})
25
},
26
- Format: MessageFormatter,
26
+ Format: MessageMarshaller,
27
Type: &MessageOutput{},
28
}
core/commands2/ls.go
+2
-2
@@ -52,7 +52,7 @@ var lsCmd = &cmds.Command{
52
53
res.SetOutput(&LsOutput{output})
54
},
55
- Format: func(res cmds.Response) (string, error) {
55
+ Format: func(res cmds.Response) ([]byte, error) {
56
s := ""
57
output := res.Output().(*LsOutput).Objects
58
@@ -70,7 +70,7 @@ var lsCmd = &cmds.Command{
70
}
71
}
72
73
- return s, nil
73
+ return []byte(s), nil
74
},
75
Type: &LsOutput{},
76
}
core/commands2/publish.go
+3
-2
@@ -61,9 +61,10 @@ var publishCmd = &cmds.Command{
61
Value: ref,
62
})
63
},
64
- Format: func(res cmds.Response) (string, error) {
64
+ Format: func(res cmds.Response) ([]byte, error) {
65
v := res.Output().(*PublishOutput)
66
- return fmt.Sprintf("Published name %s to %s\n", v.Name, v.Value), nil
66
+ s := fmt.Sprintf("Published name %s to %s\n", v.Name, v.Value)
67
+ return []byte(s), nil
68
},
69
Type: &PublishOutput{},
70
}
core/commands2/root.go
+4
-4
@@ -71,11 +71,11 @@ var rootSubcommands = map[string]*cmds.Command{
71
log.Info("beep")
72
res.SetOutput(v)
73
},
74
- Format: func(res cmds.Response) (string, error) {
74
+ Format: func(res cmds.Response) ([]byte, error) {
75
v := res.Output().(*TestOutput)
76
s := fmt.Sprintf("Foo: %s\n", v.Foo)
77
s += fmt.Sprintf("Bar: %v\n", v.Bar)
78
- return s, nil
78
+ return []byte(s), nil
79
},
80
Type: &TestOutput{},
81
},
@@ -120,6 +120,6 @@ type MessageOutput struct {
120
Message string
121
}
122
123
-func MessageFormatter(res cmds.Response) (string, error) {
124
- return res.Output().(*MessageOutput).Message, nil
123
+func MessageMarshaller(res cmds.Response) ([]byte, error) {
124
+ return []byte(res.Output().(*MessageOutput).Message), nil
125
}