github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/action/graph.go (about) 1 package action 2 3 import ( 4 "context" 5 6 "github.com/helmwave/helmwave/pkg/plan" 7 log "github.com/sirupsen/logrus" 8 "github.com/urfave/cli/v2" 9 ) 10 11 var _ Action = (*Graph)(nil) 12 13 // Graph is a struct for running 'graph' command. 14 type Graph struct { 15 build *Build 16 autoBuild bool 17 } 18 19 // Run is the main function for 'status' command. 20 func (l *Graph) Run(ctx context.Context) error { 21 if 1 == l.build.options.GraphWidth { 22 log.Info("🔺it is not possible to turn off the graph in this command") 23 24 return nil 25 } 26 27 old := l.build.options.GraphWidth 28 if l.autoBuild { 29 // Disable graph if it needs to build 30 l.build.options.GraphWidth = 1 31 if err := l.build.Run(ctx); err != nil { 32 return err 33 } 34 } 35 l.build.options.GraphWidth = old 36 37 p, err := plan.NewAndImport(ctx, l.build.plandir) 38 if err != nil { 39 return err 40 } 41 42 log.Infof("show graph:\n%s", p.BuildGraphASCII(l.build.options.GraphWidth)) 43 44 return nil 45 } 46 47 // Cmd returns 'status' *cli.Command. 48 func (l *Graph) Cmd() *cli.Command { 49 return &cli.Command{ 50 Name: "graph", 51 Category: Step1, 52 Usage: "show graph", 53 Flags: l.flags(), 54 Action: toCtx(l.Run), 55 } 56 } 57 58 // flags return flag set of CLI urfave. 59 func (l *Graph) flags() []cli.Flag { 60 // Init sub-structures 61 l.build = &Build{} 62 63 self := []cli.Flag{ 64 flagAutoBuild(&l.autoBuild), 65 } 66 67 return append(self, l.build.flags()...) 68 }