File tree Expand file tree Collapse file tree 2 files changed +4
-18
lines changed
Expand file tree Collapse file tree 2 files changed +4
-18
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ type RunOptions struct {
2828// The options parameter may be nil, in which case default values are used. See [RunOptions] for
2929// more details.
3030func Run (ctx context.Context , root * Command , options * RunOptions ) error {
31+ if ctx == nil {
32+ ctx = context .Background ()
33+ }
3134 if root == nil {
3235 return errors .New ("root command is nil" )
3336 }
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package cli
33import (
44 "bytes"
55 "context"
6- "errors"
76 "flag"
87 "strings"
98 "testing"
@@ -98,23 +97,7 @@ func TestRun(t *testing.T) {
9897 require .Contains (t , err .Error (), `unknown command "verzion". Did you mean one of these?` )
9998 require .Contains (t , err .Error (), ` version` )
10099 })
101- t .Run ("run with nil context" , func (t * testing.T ) {
102- t .Parallel ()
103- root := & Command {
104- Name : "test" ,
105- Exec : func (ctx context.Context , s * State ) error {
106- if ctx == nil {
107- return errors .New ("context is nil" )
108- }
109- return nil
110- },
111- }
112- err := Parse (root , nil )
113- require .NoError (t , err )
114- err = Run (nil , root , nil ) //nolint:staticcheck // intentionally testing nil context
115- require .Error (t , err )
116- require .Contains (t , err .Error (), "context is nil" )
117- })
100+
118101 t .Run ("command that panics during execution" , func (t * testing.T ) {
119102 t .Parallel ()
120103 root := & Command {
You can’t perform that action at this time.
0 commit comments