github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/buffalo/cmd/info.go (about) 1 package cmd 2 3 import ( 4 "context" 5 "os/exec" 6 "time" 7 8 "github.com/gobuffalo/buffalo/genny/info" 9 "github.com/gobuffalo/clara/v2/genny/rx" 10 "github.com/gobuffalo/genny/v2" 11 "github.com/gobuffalo/meta" 12 "github.com/spf13/cobra" 13 ) 14 15 var infoOptions = struct { 16 Clara *rx.Options 17 Info *info.Options 18 }{ 19 Clara: &rx.Options{}, 20 Info: &info.Options{}, 21 } 22 23 // infoCmd represents the info command 24 var infoCmd = &cobra.Command{ 25 Use: "info", 26 Short: "Print diagnostic information (useful for debugging)", 27 RunE: func(cmd *cobra.Command, args []string) error { 28 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 29 defer cancel() 30 31 run := genny.WetRunner(ctx) 32 33 _, err := run.LookPath("clara") 34 if err == nil { 35 // use the clara binary if available 36 run.WithRun(func(r *genny.Runner) error { 37 return r.Exec(exec.Command("clara")) 38 }) 39 } else { 40 // no clara binary, so use the one bundled with buffalo 41 copts := infoOptions.Clara 42 if err := run.WithNew(rx.New(copts)); err != nil { 43 return err 44 } 45 } 46 47 iopts := infoOptions.Info 48 if err := run.WithNew(info.New(iopts)); err != nil { 49 return err 50 } 51 52 return run.Run() 53 }, 54 } 55 56 func init() { 57 app := meta.New(".") 58 infoOptions.Clara.App = app 59 infoOptions.Info.App = app 60 61 decorate("info", RootCmd) 62 RootCmd.AddCommand(infoCmd) 63 }