From 1fc67011e3b6410afbc1e6829f5170d91be37568 Mon Sep 17 00:00:00 2001 From: Jason Waldrip Date: Mon, 13 Oct 2014 13:22:44 -0600 Subject: [PATCH 1/4] add errOutput --- cli/output.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/output.go b/cli/output.go index 54c0602..c2d27ff 100644 --- a/cli/output.go +++ b/cli/output.go @@ -12,6 +12,16 @@ func (cmd *CLI) ErrOutput() io.Writer { return cmd.errOutput } +// SetErrOutput sets the error output for the command +func (cmd *CLI) SetErrOutput(writer io.Writer) { + cmd.errOutput = writer +} + +// SetStdOutput sets the standard output for the command +func (cmd *CLI) SetStdOutput(writer io.Writer) { + cmd.stdOutput = writer +} + // Mute mutes the output func (cmd *CLI) Mute() { var err error From 0a431e8f8406afec21a62fcf7ec3ab18da18b00e Mon Sep 17 00:00:00 2001 From: Jason Waldrip Date: Mon, 13 Oct 2014 13:23:47 -0600 Subject: [PATCH 2/4] add a test to make things red --- cli/subcommand_parsing_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/subcommand_parsing_test.go b/cli/subcommand_parsing_test.go index ef8b351..b417367 100644 --- a/cli/subcommand_parsing_test.go +++ b/cli/subcommand_parsing_test.go @@ -1,6 +1,8 @@ package cli_test import ( + "bytes" + . "github.com/jwaldrip/odin/cli" . "github.com/onsi/ginkgo" @@ -13,8 +15,10 @@ var _ = Describe("CLI Start", func() { var cmd Command var didRun bool var didRunSub bool + var errout *bytes.Buffer BeforeEach(func() { + errout = bytes.NewBufferString("") didRun = false runFn := func(c Command) { cmd = c @@ -23,6 +27,7 @@ var _ = Describe("CLI Start", func() { cli = New("v1.0.0", "sample description", runFn) cli.ErrorHandling = PanicOnError cli.Mute() + cli.SetErrOutput(errout) didRunSub = false cli.DefineSubCommand("razzle", "razzle dazzle me", func(c Command) { didRunSub = true @@ -39,6 +44,7 @@ var _ = Describe("CLI Start", func() { Context("when the subcommand is not valid", func() { It("should raise an error", func() { Expect(func() { cli.Start("cmd", "bad") }).Should(Panic()) + Expect(errout.String()).To(ContainSubstring("invalid command: bad")) }) }) From 134ed94241473c4bd7e32db3450efbb494238114 Mon Sep 17 00:00:00 2001 From: Jason Waldrip Date: Mon, 13 Oct 2014 13:23:54 -0600 Subject: [PATCH 3/4] fix the issue to go green --- cli/subCommand_parsing.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/subCommand_parsing.go b/cli/subCommand_parsing.go index c912b6a..a2ba4c3 100644 --- a/cli/subCommand_parsing.go +++ b/cli/subCommand_parsing.go @@ -7,7 +7,8 @@ func (cmd *CLI) parseSubCommands(args []string) ([]string, bool) { name := args[0] subcmd, ok := cmd.subCommands[name] if !ok { - subcmd.errf("invalid command: %s", name) + cmd.errf("invalid command: %s", name) + return args, false } subcmd.Start(args...) From 682f38a4ba309f1d074d47cbfdea203f92219dac Mon Sep 17 00:00:00 2001 From: Jason Waldrip Date: Mon, 13 Oct 2014 13:24:40 -0600 Subject: [PATCH 4/4] bump version --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7e4d312..04c7151 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import odin "github.com/jwaldrip/odin/cli" // VERSION is the odin version -var VERSION = "1.3.0" +var VERSION = "1.3.1" var cli = odin.New(VERSION, "a command line DSL for go-lang", func(cmd odin.Command) { cmd.Usage() })