Repository: spf13/cobra
Pull request #405 (2017-03-28 17:38:53)

README: Use valid exit code value in `os.Exit` calls
Exit code value range is 0-255. I think the examples in the main README document should be valid both syntactically and semantically.

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/spf13/cobra?pullRequest=405) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/spf13/cobra?pullRequest=405) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/spf13/cobra?pullRequest=405) it.</sub>

Patch:
diff --git a/README.md b/README.md
index 2de9840..0d5bbfb 100644
--- a/README.md
+++ b/README.md
@@ -168,7 +168,7 @@ import (
 func main() {
 	if err := cmd.RootCmd.Execute(); err != nil {
 		fmt.Println(err)
-		os.Exit(-1)
+		os.Exit(1)
 	}
 }
 ```
@@ -329,7 +329,7 @@ import (
 func main() {
 	if err := cmd.RootCmd.Execute(); err != nil {
 		fmt.Println(err)
-		os.Exit(-1)
+		os.Exit(1)
 	}
 }
 ```
diff --git a/bash_completions.go b/bash_completions.go
index 8820ba8..a0d0402 100644
--- a/bash_completions.go
+++ b/bash_completions.go
@@ -88,8 +88,8 @@ __handle_reply()
                 local index flag
                 flag="${cur%%=*}"
                 __index_of_word "${flag}" "${flags_with_completion[@]}"
+                COMPREPLY=()
                 if [[ ${index} -ge 0 ]]; then
-                    COMPREPLY=()
                     PREFIX=""
                     cur="${cur#*=}"
                     ${flags_completion[${index}]}
@@ -225,7 +225,7 @@ __handle_command()
     fi
     c=$((c+1))
     __debug "${FUNCNAME[0]}: looking for ${next_command}"
-    declare -F $next_command >/dev/null && $next_command
+    declare -F "$next_command" >/dev/null && $next_command
 }
 
 __handle_word()
diff --git a/command.go b/command.go
index 664bf5a..f4cd95c 100644
--- a/command.go
+++ b/command.go
@@ -113,7 +113,7 @@ type Command struct {
 	flagErrorBuf *bytes.Buffer
 
 	args          []string             // actual args parsed from flags
-	output        *io.Writer           // out writer if set in SetOutput(w)
+	output        io.Writer            // out writer if set in SetOutput(w)
 	usageFunc     func(*Command) error // Usage can be defined by application
 	usageTemplate string               // Can be defined by Application
 	flagErrorFunc func(*Command, error) error
@@ -141,7 +141,7 @@ func (c *Command) SetArgs(a []string) {
 // SetOutput sets the destination for usage and error messages.
 // If output is nil, os.Stderr is used.
 func (c *Command) SetOutput(output io.Writer) {
-	c.output = &output
+	c.output = output
 }
 
 // SetUsageFunc sets usage function. Usage can be defined by application.
@@ -199,7 +199,7 @@ func (c *Command) OutOrStderr() io.Writer {
 
 func (c *Command) getOut(def io.Writer) io.Writer {
 	if c.output != nil {
-		return *c.output
+		return c.output
 	}
 	if c.HasParent() {
 		return c.parent.getOut(def)
@@ -341,8 +341,7 @@ func (c *Command) UsageTemplate() string {
   {{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
 
 Aliases:
-  {{.NameAndAliases}}
-{{end}}{{if .HasExample}}
+  {{.NameAndAliases}}{{end}}{{if .HasExample}}
 
 Examples:
 {{ .Example }}{{end}}{{if .HasAvailableSubCommands}}


Test patch:
diff --git a/command_test.go b/command_test.go
index 7947f6c..8b78ee3 100644
--- a/command_test.go
+++ b/command_test.go
@@ -191,6 +191,14 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) {
 	EnableCommandSorting = true
 }
 
+func TestSetOutput(t *testing.T) {
+	cmd := &Command{}
+	cmd.SetOutput(nil)
+	if out := cmd.OutOrStdout(); out != os.Stdout {
+		t.Fatalf("expected setting output to nil to revert back to stdout, got %v", out)
+	}
+}
+
 func TestFlagErrorFunc(t *testing.T) {
 
 	cmd := &Command{
diff --git a/doc/man_examples_test.go b/doc/man_examples_test.go
index 3593853..db66042 100644
--- a/doc/man_examples_test.go
+++ b/doc/man_examples_test.go
@@ -8,7 +8,7 @@ import (
 	"github.com/spf13/cobra/doc"
 )
 
-func ExampleCommand_GenManTree() {
+func ExampleGenManTree() {
 	cmd := &cobra.Command{
 		Use:   "test",
 		Short: "my test program",
@@ -20,7 +20,7 @@ func ExampleCommand_GenManTree() {
 	doc.GenManTree(cmd, header, "/tmp")
 }
 
-func ExampleCommand_GenMan() {
+func ExampleGenMan() {
 	cmd := &cobra.Command{
 		Use:   "test",
 		Short: "my test program",