istio.io/istio@v0.0.0-20240520182934-d79c90f27776/operator/cmd/mesh/profile-list.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mesh 16 17 import ( 18 "sort" 19 20 "github.com/spf13/cobra" 21 22 "istio.io/istio/operator/pkg/helm" 23 ) 24 25 type profileListArgs struct { 26 // manifestsPath is a path to a charts and profiles directory in the local filesystem with a release tgz. 27 manifestsPath string 28 } 29 30 func addProfileListFlags(cmd *cobra.Command, args *profileListArgs) { 31 cmd.PersistentFlags().StringVarP(&args.manifestsPath, "charts", "", "", ChartsDeprecatedStr) 32 cmd.PersistentFlags().StringVarP(&args.manifestsPath, "manifests", "d", "", ManifestsFlagHelpStr) 33 } 34 35 func profileListCmd(plArgs *profileListArgs) *cobra.Command { 36 return &cobra.Command{ 37 Use: "list", 38 Short: "Lists available Istio configuration profiles", 39 Long: "The list subcommand lists the available Istio configuration profiles.", 40 Args: cobra.ExactArgs(0), 41 RunE: func(cmd *cobra.Command, args []string) error { 42 return profileList(cmd, plArgs) 43 }, 44 } 45 } 46 47 // profileList list all the builtin profiles. 48 func profileList(cmd *cobra.Command, plArgs *profileListArgs) error { 49 profiles, err := helm.ListProfiles(plArgs.manifestsPath) 50 if err != nil { 51 return err 52 } 53 if len(profiles) == 0 { 54 cmd.Println("No profiles available.") 55 } else { 56 cmd.Println("Istio configuration profiles:") 57 sort.Strings(profiles) 58 for _, profile := range profiles { 59 cmd.Printf(" %s\n", profile) 60 } 61 } 62 63 return nil 64 }