@@ -10,7 +10,6 @@ import (
10
10
11
11
"github.com/bep/simplecobra"
12
12
qt "github.com/frankban/quicktest"
13
- "github.com/spf13/cobra"
14
13
)
15
14
16
15
func testCommands () * rootCommand {
@@ -267,7 +266,7 @@ func (c *rootCommand) Commands() []simplecobra.Commander {
267
266
return c .commands
268
267
}
269
268
270
- func (c * rootCommand ) Init (this , runner * simplecobra.Commandeer ) error {
269
+ func (c * rootCommand ) PreRun (this , runner * simplecobra.Commandeer ) error {
271
270
c .isInit = true
272
271
c .persistentFlagNameC = c .persistentFlagName + "_rootCommand_compiled"
273
272
c .localFlagNameC = c .localFlagName + "_rootCommand_compiled"
@@ -288,10 +287,11 @@ func (c *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
288
287
return nil
289
288
}
290
289
291
- func (c * rootCommand ) WithCobraCommand ( cmd * cobra. Command ) error {
290
+ func (c * rootCommand ) Init ( cd * simplecobra. Commandeer ) error {
292
291
if c .failWithCobraCommand {
293
292
return errors .New ("failWithCobraCommand" )
294
293
}
294
+ cmd := cd .CobraCommand
295
295
localFlags := cmd .Flags ()
296
296
persistentFlags := cmd .PersistentFlags ()
297
297
@@ -323,7 +323,7 @@ func (c *lvl1Command) Commands() []simplecobra.Commander {
323
323
return c .commands
324
324
}
325
325
326
- func (c * lvl1Command ) Init (this , runner * simplecobra.Commandeer ) error {
326
+ func (c * lvl1Command ) PreRun (this , runner * simplecobra.Commandeer ) error {
327
327
if c .failInit {
328
328
return fmt .Errorf ("failInit" )
329
329
}
@@ -342,10 +342,11 @@ func (c *lvl1Command) Run(ctx context.Context, cd *simplecobra.Commandeer, args
342
342
return nil
343
343
}
344
344
345
- func (c * lvl1Command ) WithCobraCommand ( cmd * cobra. Command ) error {
345
+ func (c * lvl1Command ) Init ( cd * simplecobra. Commandeer ) error {
346
346
if c .failWithCobraCommand {
347
347
return errors .New ("failWithCobraCommand" )
348
348
}
349
+ cmd := cd .CobraCommand
349
350
cmd .DisableSuggestions = c .disableSuggestions
350
351
localFlags := cmd .Flags ()
351
352
localFlags .StringVar (& c .localFlagName , "localFlagName" , "" , "set localFlagName for lvl1Command" )
@@ -366,7 +367,7 @@ func (c *lvl2Command) Commands() []simplecobra.Commander {
366
367
return nil
367
368
}
368
369
369
- func (c * lvl2Command ) Init (this , runner * simplecobra.Commandeer ) error {
370
+ func (c * lvl2Command ) PreRun (this , runner * simplecobra.Commandeer ) error {
370
371
c .isInit = true
371
372
c .rootCmd = this .Root .Command .(* rootCommand )
372
373
c .parentCmd = this .Parent .Command .(* lvl1Command )
@@ -382,7 +383,8 @@ func (c *lvl2Command) Run(ctx context.Context, cd *simplecobra.Commandeer, args
382
383
return nil
383
384
}
384
385
385
- func (c * lvl2Command ) WithCobraCommand (cmd * cobra.Command ) error {
386
+ func (c * lvl2Command ) Init (cd * simplecobra.Commandeer ) error {
387
+ cmd := cd .CobraCommand
386
388
localFlags := cmd .Flags ()
387
389
localFlags .StringVar (& c .localFlagName , "localFlagName" , "" , "set localFlagName for lvl2Command" )
388
390
return nil
0 commit comments