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{ ...@@ -55,17 +55,18 @@ var addCmd = &cmds.Command{
res.SetOutput(&AddOutput{added}) res.SetOutput(&AddOutput{added})
}, },
Format: func(res cmds.Response) (string, error) { Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*AddOutput).Added v := res.Output().(*AddOutput).Added
if len(v) == 1 { 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)) s := fmt.Sprintf("Added %v objects:\n", len(v))
for _, obj := range v { for _, obj := range v {
s += fmt.Sprintf("- %s\n", obj.Hash) s += fmt.Sprintf("- %s\n", obj.Hash)
} }
return s, nil return []byte(s), nil
}, },
Type: &AddOutput{}, Type: &AddOutput{},
} }
......
...@@ -18,9 +18,10 @@ var commandsCmd = &cmds.Command{ ...@@ -18,9 +18,10 @@ var commandsCmd = &cmds.Command{
root := outputCommand("ipfs", Root) root := outputCommand("ipfs", Root)
res.SetOutput(&root) res.SetOutput(&root)
}, },
Format: func(res cmds.Response) (string, error) { Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*Command) v := res.Output().(*Command)
return formatCommand(v, 0), nil s := formatCommand(v, 0)
return []byte(s), nil
}, },
Type: &Command{}, Type: &Command{},
} }
......
...@@ -23,6 +23,6 @@ var logCmd = &cmds.Command{ ...@@ -23,6 +23,6 @@ var logCmd = &cmds.Command{
s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1]) s := fmt.Sprintf("Changed log level of '%s' to '%s'", args[0], args[1])
res.SetOutput(&MessageOutput{s}) res.SetOutput(&MessageOutput{s})
}, },
Format: MessageFormatter, Format: MessageMarshaller,
Type: &MessageOutput{}, Type: &MessageOutput{},
} }
...@@ -52,7 +52,7 @@ var lsCmd = &cmds.Command{ ...@@ -52,7 +52,7 @@ var lsCmd = &cmds.Command{
res.SetOutput(&LsOutput{output}) res.SetOutput(&LsOutput{output})
}, },
Format: func(res cmds.Response) (string, error) { Format: func(res cmds.Response) ([]byte, error) {
s := "" s := ""
output := res.Output().(*LsOutput).Objects output := res.Output().(*LsOutput).Objects
...@@ -70,7 +70,7 @@ var lsCmd = &cmds.Command{ ...@@ -70,7 +70,7 @@ var lsCmd = &cmds.Command{
} }
} }
return s, nil return []byte(s), nil
}, },
Type: &LsOutput{}, Type: &LsOutput{},
} }
...@@ -61,9 +61,10 @@ var publishCmd = &cmds.Command{ ...@@ -61,9 +61,10 @@ var publishCmd = &cmds.Command{
Value: ref, Value: ref,
}) })
}, },
Format: func(res cmds.Response) (string, error) { Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*PublishOutput) 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{}, Type: &PublishOutput{},
} }
...@@ -71,11 +71,11 @@ var rootSubcommands = map[string]*cmds.Command{ ...@@ -71,11 +71,11 @@ var rootSubcommands = map[string]*cmds.Command{
log.Info("beep") log.Info("beep")
res.SetOutput(v) res.SetOutput(v)
}, },
Format: func(res cmds.Response) (string, error) { Format: func(res cmds.Response) ([]byte, error) {
v := res.Output().(*TestOutput) v := res.Output().(*TestOutput)
s := fmt.Sprintf("Foo: %s\n", v.Foo) s := fmt.Sprintf("Foo: %s\n", v.Foo)
s += fmt.Sprintf("Bar: %v\n", v.Bar) s += fmt.Sprintf("Bar: %v\n", v.Bar)
return s, nil return []byte(s), nil
}, },
Type: &TestOutput{}, Type: &TestOutput{},
}, },
...@@ -120,6 +120,6 @@ type MessageOutput struct { ...@@ -120,6 +120,6 @@ type MessageOutput struct {
Message string Message string
} }
func MessageFormatter(res cmds.Response) (string, error) { func MessageMarshaller(res cmds.Response) ([]byte, error) {
return res.Output().(*MessageOutput).Message, nil 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