istio.io/istio@v0.0.0-20240520182934-d79c90f27776/istioctl/pkg/util/common.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 util 16 17 import ( 18 "fmt" 19 "io" 20 "strings" 21 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 24 binversion "istio.io/istio/operator/version" 25 ) 26 27 var NeverMatch = &metav1.LabelSelector{ 28 MatchLabels: map[string]string{ 29 "istio.io/deactivated": "never-match", 30 }, 31 } 32 33 var ManifestsFlagHelpStr = `Specify a path to a directory of charts and profiles 34 (e.g. ~/Downloads/istio-` + binversion.OperatorVersionString + `/manifests).` 35 36 // CommandParseError distinguishes an error parsing istioctl CLI arguments from an error processing 37 type CommandParseError struct { 38 Err error 39 } 40 41 func (c CommandParseError) Error() string { 42 return c.Err.Error() 43 } 44 45 // Confirm waits for a user to confirm with the supplied message. 46 func Confirm(msg string, writer io.Writer) bool { 47 for { 48 _, _ = fmt.Fprintf(writer, "%s ", msg) 49 var response string 50 _, err := fmt.Scanln(&response) 51 if err != nil { 52 return false 53 } 54 switch strings.ToUpper(response) { 55 case "Y", "YES": 56 return true 57 case "N", "NO": 58 return false 59 } 60 } 61 }