github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/instrumentation/prompt/prompt.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package prompt 18 19 import ( 20 "io" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" 23 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation" 24 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/output" 25 ) 26 27 const Prompt = `To help improve the quality of this product, we collect anonymized usage data for details on what is tracked and how we use this data visit <https://skaffold.dev/docs/resources/telemetry/>. This data is handled in accordance with our privacy policy <https://policies.google.com/privacy> 28 29 You may choose to opt out of this collection by running the following command: 30 skaffold config set --global collect-metrics false 31 ` 32 33 var ( 34 // for testing 35 isStdOut = output.IsStdout 36 updateConfig = config.UpdateGlobalCollectMetrics 37 getConfig = config.GetConfigForCurrentKubectx 38 setStatus = instrumentation.SetOnlineStatus 39 ) 40 41 // ShouldDisplayMetricsPrompt returns true if metrics is not enabled. 42 func ShouldDisplayMetricsPrompt(configfile string) bool { 43 cfg, err := getConfig(configfile) 44 if err != nil { 45 return false 46 } 47 if cfg == nil || cfg.CollectMetrics == nil { 48 return true 49 } 50 instrumentation.ShouldExportMetrics = *cfg.CollectMetrics 51 setStatus() 52 return false 53 } 54 55 func DisplayMetricsPrompt(configFile string, out io.Writer) error { 56 if isStdOut(out) { 57 output.Green.Fprintf(out, Prompt) 58 return updateConfig(configFile, true) 59 } 60 return nil 61 }