1- package cobrakai_test
1+ package simplecobra_test
22
33import (
44 "context"
55 "fmt"
66 "log"
77 "testing"
88
9- "github.com/bep/cobrakai "
9+ "github.com/bep/simplecobra "
1010 qt "github.com/frankban/quicktest"
1111 "github.com/spf13/cobra"
1212)
1313
1414func testCommands () * rootCommand {
1515 return & rootCommand {name : "root" ,
16- commands : []cobrakai .Commander {
16+ commands : []simplecobra .Commander {
1717 & lvl1Command {name : "foo" },
1818 & lvl1Command {name : "bar" ,
19- commands : []cobrakai .Commander {
19+ commands : []simplecobra .Commander {
2020 & lvl2Command {name : "baz" },
2121 },
2222 },
@@ -25,12 +25,12 @@ func testCommands() *rootCommand {
2525
2626}
2727
28- func TestCobraKai (t * testing.T ) {
28+ func TestSimplecobra (t * testing.T ) {
2929 c := qt .New (t )
3030
3131 rootCmd := testCommands ()
3232
33- x , err := cobrakai .New (rootCmd )
33+ x , err := simplecobra .New (rootCmd )
3434 c .Assert (err , qt .IsNil )
3535 // This can be anything, just used to make sure the same context is passed all the way.
3636 type key string
@@ -80,49 +80,49 @@ func TestErrors(t *testing.T) {
8080 c := qt .New (t )
8181
8282 c .Run ("unknown similar command" , func (c * qt.C ) {
83- x , err := cobrakai .New (testCommands ())
83+ x , err := simplecobra .New (testCommands ())
8484 c .Assert (err , qt .IsNil )
8585 _ , err = x .Execute (context .Background (), []string {"fooo" })
8686 c .Assert (err , qt .Not (qt .IsNil ))
8787 c .Assert (err .Error (), qt .Contains , "unknown" )
8888 c .Assert (err .Error (), qt .Contains , "Did you mean this?" )
89- c .Assert (cobrakai .IsCommandError (err ), qt .Equals , true )
89+ c .Assert (simplecobra .IsCommandError (err ), qt .Equals , true )
9090 })
9191
9292 c .Run ("unknown similar sub command" , func (c * qt.C ) {
93- x , err := cobrakai .New (testCommands ())
93+ x , err := simplecobra .New (testCommands ())
9494 c .Assert (err , qt .IsNil )
9595 _ , err = x .Execute (context .Background (), []string {"bar" , "bazz" })
9696 c .Assert (err , qt .Not (qt .IsNil ))
9797 c .Assert (err .Error (), qt .Contains , "unknown" )
9898 c .Assert (err .Error (), qt .Contains , "Did you mean this?" )
99- c .Assert (cobrakai .IsCommandError (err ), qt .Equals , true )
99+ c .Assert (simplecobra .IsCommandError (err ), qt .Equals , true )
100100 })
101101
102102 c .Run ("unknown flag" , func (c * qt.C ) {
103- x , err := cobrakai .New (testCommands ())
103+ x , err := simplecobra .New (testCommands ())
104104 c .Assert (err , qt .IsNil )
105105 _ , err = x .Execute (context .Background (), []string {"bar" , "--unknown" })
106106 c .Assert (err , qt .Not (qt .IsNil ))
107107 c .Assert (err .Error (), qt .Contains , "unknown" )
108- c .Assert (cobrakai .IsCommandError (err ), qt .Equals , true )
108+ c .Assert (simplecobra .IsCommandError (err ), qt .Equals , true )
109109 })
110110
111111}
112112
113113func Example () {
114114 rootCmd := & rootCommand {name : "root" ,
115- commands : []cobrakai .Commander {
115+ commands : []simplecobra .Commander {
116116 & lvl1Command {name : "foo" },
117117 & lvl1Command {name : "bar" ,
118- commands : []cobrakai .Commander {
118+ commands : []simplecobra .Commander {
119119 & lvl2Command {name : "baz" },
120120 },
121121 },
122122 },
123123 }
124124
125- x , err := cobrakai .New (rootCmd )
125+ x , err := simplecobra .New (rootCmd )
126126 if err != nil {
127127 log .Fatal (err )
128128 }
@@ -156,14 +156,14 @@ type rootCommand struct {
156156 ctx context.Context
157157
158158 // Sub commands.
159- commands []cobrakai .Commander
159+ commands []simplecobra .Commander
160160}
161161
162- func (c * rootCommand ) Commands () []cobrakai .Commander {
162+ func (c * rootCommand ) Commands () []simplecobra .Commander {
163163 return c .commands
164164}
165165
166- func (c * rootCommand ) Init (* cobrakai .Commandeer ) error {
166+ func (c * rootCommand ) Init (* simplecobra .Commandeer ) error {
167167 c .persistentFlagNameC = c .persistentFlagName + "_rootCommand_compiled"
168168 c .localFlagNameC = c .localFlagName + "_rootCommand_compiled"
169169 return nil
@@ -196,16 +196,16 @@ type lvl1Command struct {
196196
197197 rootCmd * rootCommand
198198
199- commands []cobrakai .Commander
199+ commands []simplecobra .Commander
200200
201201 ctx context.Context
202202}
203203
204- func (c * lvl1Command ) Commands () []cobrakai .Commander {
204+ func (c * lvl1Command ) Commands () []simplecobra .Commander {
205205 return c .commands
206206}
207207
208- func (c * lvl1Command ) Init (cd * cobrakai .Commandeer ) error {
208+ func (c * lvl1Command ) Init (cd * simplecobra .Commandeer ) error {
209209 c .localFlagNameC = c .localFlagName + "_lvl1Command_compiled"
210210 c .rootCmd = cd .Root .Command .(* rootCommand )
211211 return nil
@@ -235,11 +235,11 @@ type lvl2Command struct {
235235 parentCmd * lvl1Command
236236}
237237
238- func (c * lvl2Command ) Commands () []cobrakai .Commander {
238+ func (c * lvl2Command ) Commands () []simplecobra .Commander {
239239 return nil
240240}
241241
242- func (c * lvl2Command ) Init (cd * cobrakai .Commandeer ) error {
242+ func (c * lvl2Command ) Init (cd * simplecobra .Commandeer ) error {
243243 c .rootCmd = cd .Root .Command .(* rootCommand )
244244 c .parentCmd = cd .Parent .Command .(* lvl1Command )
245245 return nil
0 commit comments