Skip to content
Myr

Avoid storing pointer to nil (#411)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Fix shellcheck Before this change: In - line 204: declare -F $next_command >/dev/null && $next_command ^-- SC2086: Double quote to prevent globbing and word splitting. --- FAIL: TestBashCompletions (0.34s) bash_completions_test.go:138: shellcheck failed: exit status 1 * Avoid storing pointer to nil Before this change, the new test fails with: --- FAIL: TestSetOutput (0.00s) command_test.go:198: expected setting output to nil to revert back to stdout, got <nil>

authored by Tamir Duberstein · committed by Eric Paris · parent 6421115 · Browse files · 3 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−4 removed

  • other:+12 added−4 removed

3 files+12 added−4 removed

modified:bash_completions.go+1 added-1 removed
223 unmodified lines
224 fi225 fi226 c=$((c+1))227 __debug "${FUNCNAME[0]}: looking for ${next_command}"228 declare -F $next_command >/dev/null && $next_command228 declare -F "$next_command" >/dev/null && $next_command229}230231__handle_word()232{
413 unmodified lines
modified:command_test.go+8 added
189 unmodified lines
190191 EnableCommandSorting = true192}193194func TestSetOutput(t *testing.T) {195 cmd := &Command{}196 cmd.SetOutput(nil)197 if out := cmd.OutOrStdout(); out != os.Stdout {198 t.Fatalf("expected setting output to nil to revert back to stdout, got %v", out)199 }200}201202func TestFlagErrorFunc(t *testing.T) {203204 cmd := &Command{205 Use: "print",
19 unmodified lines
modified:command.go+3 added-3 removed
111 unmodified lines
112113 flagErrorBuf *bytes.Buffer114115 args []string // actual args parsed from flags116 output *io.Writer // out writer if set in SetOutput(w)116 output io.Writer // out writer if set in SetOutput(w)117 usageFunc func(*Command) error // Usage can be defined by application118 usageTemplate string // Can be defined by Application119 flagErrorFunc func(*Command, error) error120 helpTemplate string // Can be defined by Application
19 unmodified lines
140141// SetOutput sets the destination for usage and error messages.142// If output is nil, os.Stderr is used.143func (c *Command) SetOutput(output io.Writer) {144 c.output = &output144 c.output = output145}146147// SetUsageFunc sets usage function. Usage can be defined by application.148func (c *Command) SetUsageFunc(f func(*Command) error) {
49 unmodified lines
198}199200func (c *Command) getOut(def io.Writer) io.Writer {201 if c.output != nil {202 return *c.output202 return c.output203 }204 if c.HasParent() {205 return c.parent.getOut(def)206 }
1100 unmodified lines