Commit 0afd3391 authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

commands: Replaced 'Formatter' with 'Marshaller'

parent 3dd7a9a5
......@@ -55,17 +55,18 @@ var addCmd = &cmds.Command{
res.SetOutput(&AddOutput{added})
},
Format: func(res cmds.Response) (string, error) {
Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*AddOutput).Added
if len(v) == 1 {
return fmt.Sprintf("Added object: %s\n", v[0].Hash), nil
s := fmt.Sprintf("Added object: %s\n", v[0].Hash)
return []byte(s), nil
}
s := fmt.Sprintf("Added %v objects:\n", len(v))
for _, obj := range v {
s += fmt.Sprintf("- %s\n", obj.Hash)
}
return s, nil
return []byte(s), nil
},
Type: &AddOutput{},
}
......
......@@ -18,9 +18,10 @@ var commandsCmd = &cmds.Command{
root := outputCommand("ipfs", Root)
res.SetOutput(&root)
},
Format: func(res cmds.Response) (string, error) {
Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*Command)
return formatCommand(v, 0), nil
s := formatCommand(v, 0)
return []byte(s), nil
},
Type: &Command{},
}
......
......@@ -23,6 +23,6 @@ var logCmd = &cmds.Command{
s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
res.SetOutput(&MessageOutput{s})
},
Format: MessageFormatter,
Format: MessageMarshaller,
Type: &MessageOutput{},
}
......@@ -52,7 +52,7 @@ var lsCmd = &cmds.Command{
res.SetOutput(&LsOutput{output})
},
Format: func(res cmds.Response) (string, error) {
Format: func(res cmds.Response) ([]byte, error) {
s := ""
output := res.Output().(*LsOutput).Objects
......@@ -70,7 +70,7 @@ var lsCmd = &cmds.Command{
}
}
return s, nil
return []byte(s), nil
},
Type: &LsOutput{},
}
......@@ -61,9 +61,10 @@ var publishCmd = &cmds.Command{
Value: ref,
})
},
Format: func(res cmds.Response) (string, error) {
Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*PublishOutput)
return fmt.Sprintf("Published name %s to %s\n", v.Name, v.Value), nil
s := fmt.Sprintf("Published name %s to %s\n", v.Name, v.Value)
return []byte(s), nil
},
Type: &PublishOutput{},
}
......@@ -71,11 +71,11 @@ var rootSubcommands = map[string]*cmds.Command{
log.Info("beep")
res.SetOutput(v)
},
Format: func(res cmds.Response) (string, error) {
Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*TestOutput)
s := fmt.Sprintf("Foo: %s\n", v.Foo)
s += fmt.Sprintf("Bar: %v\n", v.Bar)
return s, nil
return []byte(s), nil
},
Type: &TestOutput{},
},
......@@ -120,6 +120,6 @@ type MessageOutput struct {
Message string
}
func MessageFormatter(res cmds.Response) (string, error) {
return res.Output().(*MessageOutput).Message, nil
func MessageMarshaller(res cmds.Response) ([]byte, error) {
return []byte(res.Output().(*MessageOutput).Message), nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment