github.com/verrazzano/verrazzano@v1.7.1/tools/psr/psrctl/cmd/explain/explain.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package explain 5 6 import ( 7 "fmt" 8 9 "github.com/spf13/cobra" 10 "github.com/verrazzano/verrazzano/pkg/log/vzlog" 11 "github.com/verrazzano/verrazzano/tools/psr/psrctl/cmd/constants" 12 "github.com/verrazzano/verrazzano/tools/psr/psrctl/pkg/manifest" 13 cmdhelpers "github.com/verrazzano/verrazzano/tools/vz/cmd/helpers" 14 "github.com/verrazzano/verrazzano/tools/vz/pkg/helpers" 15 ) 16 17 const ( 18 CommandName = "explain" 19 helpShort = "Describe PSR scenarios that can be started" 20 helpLong = `The command 'explain' describes scenarios that can be started. The scenarios are represented by 21 manifest files built into the psrctl binary.` 22 helpExample = ` 23 psrctl explain 24 psrctl explain -s ops-s1` 25 ) 26 27 var scenarioID string 28 var verbose bool 29 30 func NewCmdExplain(vzHelper helpers.VZHelper) *cobra.Command { 31 cmd := cmdhelpers.NewCommand(vzHelper, CommandName, helpShort, helpLong) 32 cmd.RunE = func(cmd *cobra.Command, args []string) error { 33 return RunCmdExplain(cmd, vzHelper) 34 } 35 cmd.Example = helpExample 36 37 cmd.PersistentFlags().StringVarP(&scenarioID, constants.FlagScenario, constants.FlagsScenarioShort, "", constants.FlagScenarioHelp) 38 cmd.PersistentFlags().BoolVarP(&verbose, constants.FlagVerbose, constants.FlagVerboseShort, false, constants.FlagVerboseHelp) 39 40 return cmd 41 } 42 43 // RunCmdExplain - explain the "psrctl explain" command 44 func RunCmdExplain(cmd *cobra.Command, vzHelper helpers.VZHelper) error { 45 fmt.Fprintln(vzHelper.GetOutputStream()) 46 fmt.Fprintln(vzHelper.GetOutputStream(), "Listing available scenarios ...") 47 48 m := manifest.ManifestManager{ 49 Log: vzlog.DefaultLogger(), 50 Manifest: *manifest.Manifests, 51 } 52 53 scs, err := m.ListScenarioManifests() 54 if err != nil { 55 return fmt.Errorf("Failed to list scenario manifests: %s", err) 56 } 57 for _, sc := range scs { 58 if len(scenarioID) > 0 && sc.ID != scenarioID { 59 continue 60 } 61 fmt.Fprintln(vzHelper.GetOutputStream(), "----------------") 62 fmt.Fprintln(vzHelper.GetOutputStream()) 63 fmt.Fprintf(vzHelper.GetOutputStream(), "ID: %s\n", sc.ID) 64 fmt.Fprintf(vzHelper.GetOutputStream(), "Name: %s\n", sc.Name) 65 fmt.Fprintf(vzHelper.GetOutputStream(), "Description: %s\n", sc.Description) 66 67 // If verbose 68 if verbose { 69 fmt.Fprintln(vzHelper.GetOutputStream(), "Use cases:") 70 for _, uc := range sc.Usecases { 71 fmt.Fprintf(vzHelper.GetOutputStream(), "Usecase path %s: Description: %s\n", uc.UsecasePath, uc.Description) 72 } 73 } 74 if len(scenarioID) > 0 && sc.ID == scenarioID { 75 break 76 } 77 } 78 fmt.Fprintln(vzHelper.GetOutputStream()) 79 80 return nil 81 }