github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/cmd/tool_event.go (about) 1 // Copyright (c) 2018-2021, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package cmd 6 7 import ( 8 "sync" 9 10 lifecycle "github.com/choria-io/go-choria/lifecycle" 11 ) 12 13 type tEventCommand struct { 14 command 15 16 componentF string 17 typeF string 18 } 19 20 func (e *tEventCommand) Setup() (err error) { 21 if tool, ok := cmdWithFullCommand("tool"); ok { 22 e.cmd = tool.Cmd().Command("event", "View Choria lifecycle events") 23 e.cmd.Flag("component", "Limit events to a named component").StringVar(&e.componentF) 24 e.cmd.Flag("type", "Limits the events to a particular type").EnumVar(&e.typeF, lifecycle.EventTypeNames()...) 25 } 26 27 return nil 28 } 29 30 func (e *tEventCommand) Configure() error { 31 return commonConfigure() 32 } 33 34 func (e *tEventCommand) Run(wg *sync.WaitGroup) (err error) { 35 defer wg.Done() 36 37 opt := &lifecycle.ViewOptions{ 38 Choria: c, 39 ComponentFilter: e.componentF, 40 TypeFilter: e.typeF, 41 Debug: debug, 42 } 43 44 lifecycle.View(ctx, opt) 45 46 return nil 47 } 48 49 func init() { 50 cli.commands = append(cli.commands, &tEventCommand{}) 51 }