github.com/wawandco/oxpecker-plugins@v0.1.1/tools/pop/command.go (about) 1 package pop 2 3 import ( 4 "context" 5 "errors" 6 7 "github.com/wawandco/oxpecker-plugins/tools/pop/migrate" 8 "github.com/wawandco/oxpecker/plugins" 9 ) 10 11 // Ensuring pop.Plugin is a command 12 var _ plugins.Command = (*Plugin)(nil) 13 14 //HelpText resturns the help Text of build function 15 func (b Plugin) HelpText() string { 16 return "provides commands for pop common tasks" 17 } 18 19 func (b *Plugin) Receive(plugins []plugins.Plugin) { 20 for _, plugin := range plugins { 21 if mig, ok := plugin.(*migrate.Plugin); ok { 22 b.subcommands = append(b.subcommands, mig) 23 continue 24 } 25 26 // Other subcommands 27 } 28 } 29 30 func (b *Plugin) Run(ctx context.Context, root string, args []string) error { 31 if len(args) < 2 { 32 return errors.New("subcommand not found") 33 } 34 35 for _, cm := range b.subcommands { 36 if cm.Name() != args[1] { 37 continue 38 } 39 40 if fp, ok := cm.(plugins.FlagParser); ok { 41 fp.ParseFlags(args[1:]) 42 } 43 44 return cm.Run(ctx, root, args[1:]) 45 } 46 47 return nil 48 } 49 50 func (b *Plugin) Subcommands() []plugins.Command { 51 return b.subcommands 52 }