github.com/sleungcy-sap/cli@v7.1.0+incompatible/command/v7/buildpacks_command.go (about) 1 package v7 2 3 import ( 4 "strconv" 5 6 "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/util/ui" 8 ) 9 10 type BuildpacksCommand struct { 11 BaseCommand 12 13 usage interface{} `usage:"CF_NAME buildpacks [--labels SELECTOR]\n\nEXAMPLES:\n CF_NAME buildpacks\n CF_NAME buildpacks --labels 'environment in (production,staging),tier in (backend)'\n CF_NAME buildpacks --labels 'env=dev,!chargeback-code,tier in (backend,worker)'"` 14 relatedCommands interface{} `related_commands:"create-buildpack, delete-buildpack, rename-buildpack, update-buildpack"` 15 Labels string `long:"labels" description:"Selector to filter buildpacks by labels"` 16 } 17 18 func (cmd BuildpacksCommand) Execute(args []string) error { 19 err := cmd.SharedActor.CheckTarget(false, false) 20 if err != nil { 21 return err 22 } 23 24 user, err := cmd.Config.CurrentUser() 25 if err != nil { 26 return err 27 } 28 29 cmd.UI.DisplayTextWithFlavor("Getting buildpacks as {{.Username}}...", map[string]interface{}{ 30 "Username": user.Name, 31 }) 32 cmd.UI.DisplayNewline() 33 34 buildpacks, warnings, err := cmd.Actor.GetBuildpacks(cmd.Labels) 35 cmd.UI.DisplayWarnings(warnings) 36 if err != nil { 37 return err 38 } 39 40 if len(buildpacks) == 0 { 41 cmd.UI.DisplayTextWithFlavor("No buildpacks found") 42 } else { 43 cmd.displayTable(buildpacks) 44 } 45 return nil 46 } 47 48 func (cmd BuildpacksCommand) displayTable(buildpacks []v7action.Buildpack) { 49 if len(buildpacks) > 0 { 50 var keyValueTable = [][]string{ 51 {"position", "name", "stack", "enabled", "locked", "filename"}, 52 } 53 for _, buildpack := range buildpacks { 54 keyValueTable = append(keyValueTable, []string{ 55 strconv.Itoa(buildpack.Position.Value), 56 buildpack.Name, 57 buildpack.Stack, 58 strconv.FormatBool(buildpack.Enabled.Value), 59 strconv.FormatBool(buildpack.Locked.Value), 60 buildpack.Filename, 61 }) 62 } 63 64 cmd.UI.DisplayTableWithHeader("", keyValueTable, ui.DefaultTableSpacePadding) 65 } 66 }