@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/bep/simplecobra"
1212 qt "github.com/frankban/quicktest"
13- "github.com/spf13/cobra"
1413)
1514
1615func testCommands () * rootCommand {
@@ -267,7 +266,7 @@ func (c *rootCommand) Commands() []simplecobra.Commander {
267266 return c .commands
268267}
269268
270- func (c * rootCommand ) Init (this , runner * simplecobra.Commandeer ) error {
269+ func (c * rootCommand ) PreRun (this , runner * simplecobra.Commandeer ) error {
271270 c .isInit = true
272271 c .persistentFlagNameC = c .persistentFlagName + "_rootCommand_compiled"
273272 c .localFlagNameC = c .localFlagName + "_rootCommand_compiled"
@@ -288,10 +287,11 @@ func (c *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
288287 return nil
289288}
290289
291- func (c * rootCommand ) WithCobraCommand ( cmd * cobra. Command ) error {
290+ func (c * rootCommand ) Init ( cd * simplecobra. Commandeer ) error {
292291 if c .failWithCobraCommand {
293292 return errors .New ("failWithCobraCommand" )
294293 }
294+ cmd := cd .CobraCommand
295295 localFlags := cmd .Flags ()
296296 persistentFlags := cmd .PersistentFlags ()
297297
@@ -323,7 +323,7 @@ func (c *lvl1Command) Commands() []simplecobra.Commander {
323323 return c .commands
324324}
325325
326- func (c * lvl1Command ) Init (this , runner * simplecobra.Commandeer ) error {
326+ func (c * lvl1Command ) PreRun (this , runner * simplecobra.Commandeer ) error {
327327 if c .failInit {
328328 return fmt .Errorf ("failInit" )
329329 }
@@ -342,10 +342,11 @@ func (c *lvl1Command) Run(ctx context.Context, cd *simplecobra.Commandeer, args
342342 return nil
343343}
344344
345- func (c * lvl1Command ) WithCobraCommand ( cmd * cobra. Command ) error {
345+ func (c * lvl1Command ) Init ( cd * simplecobra. Commandeer ) error {
346346 if c .failWithCobraCommand {
347347 return errors .New ("failWithCobraCommand" )
348348 }
349+ cmd := cd .CobraCommand
349350 cmd .DisableSuggestions = c .disableSuggestions
350351 localFlags := cmd .Flags ()
351352 localFlags .StringVar (& c .localFlagName , "localFlagName" , "" , "set localFlagName for lvl1Command" )
@@ -366,7 +367,7 @@ func (c *lvl2Command) Commands() []simplecobra.Commander {
366367 return nil
367368}
368369
369- func (c * lvl2Command ) Init (this , runner * simplecobra.Commandeer ) error {
370+ func (c * lvl2Command ) PreRun (this , runner * simplecobra.Commandeer ) error {
370371 c .isInit = true
371372 c .rootCmd = this .Root .Command .(* rootCommand )
372373 c .parentCmd = this .Parent .Command .(* lvl1Command )
@@ -382,7 +383,8 @@ func (c *lvl2Command) Run(ctx context.Context, cd *simplecobra.Commandeer, args
382383 return nil
383384}
384385
385- func (c * lvl2Command ) WithCobraCommand (cmd * cobra.Command ) error {
386+ func (c * lvl2Command ) Init (cd * simplecobra.Commandeer ) error {
387+ cmd := cd .CobraCommand
386388 localFlags := cmd .Flags ()
387389 localFlags .StringVar (& c .localFlagName , "localFlagName" , "" , "set localFlagName for lvl2Command" )
388390 return nil
0 commit comments