From 0afd3391a8e630bcb4b0cb80fc157053dbfa0779 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 3 Nov 2014 23:02:50 -0800 Subject: [PATCH] commands: Replaced 'Formatter' with 'Marshaller' --- core/commands2/add.go | 7 ++++--- core/commands2/commands.go | 5 +++-- core/commands2/log.go | 2 +- core/commands2/ls.go | 4 ++-- core/commands2/publish.go | 5 +++-- core/commands2/root.go | 8 ++++---- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/commands2/add.go b/core/commands2/add.go index 056c904d2..aacb5c9e1 100644 --- a/core/commands2/add.go +++ b/core/commands2/add.go @@ -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{}, } diff --git a/core/commands2/commands.go b/core/commands2/commands.go index 365ebd04d..bc40faabe 100644 --- a/core/commands2/commands.go +++ b/core/commands2/commands.go @@ -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{}, } diff --git a/core/commands2/log.go b/core/commands2/log.go index d5a042b9f..534c8a07f 100644 --- a/core/commands2/log.go +++ b/core/commands2/log.go @@ -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{}, } diff --git a/core/commands2/ls.go b/core/commands2/ls.go index ec8840c87..a100f6884 100644 --- a/core/commands2/ls.go +++ b/core/commands2/ls.go @@ -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{}, } diff --git a/core/commands2/publish.go b/core/commands2/publish.go index 06f43dab2..08c75c0c1 100644 --- a/core/commands2/publish.go +++ b/core/commands2/publish.go @@ -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{}, } diff --git a/core/commands2/root.go b/core/commands2/root.go index 1a971aae9..37df2c899 100644 --- a/core/commands2/root.go +++ b/core/commands2/root.go @@ -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 }