From c9830de736fd2b2c394c52aefc77e916f02bc8ab Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 28 Mar 2024 19:13:33 +0000 Subject: [PATCH] chore: Update CLI prompt to run command as root (#1517) --- cmd/troubleshoot/cli/run.go | 3 +-- internal/util/util.go | 2 ++ pkg/preflight/run.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index dd0171c14..92d8ec370 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -113,9 +113,8 @@ func runTroubleshoot(v *viper.Viper, args []string) error { if interactive { if len(mainBundle.Spec.HostCollectors) > 0 && !util.IsRunningAsRoot() { - msg := "Some host collectors may require elevated privileges to run.\nDo you want to exit and rerun the command as a privileged user?" fmt.Print(cursor.Show()) - if util.PromptYesNo(msg) { + if util.PromptYesNo(util.HOST_COLLECTORS_RUN_AS_ROOT_PROMPT) { fmt.Println("Exiting...") return nil } diff --git a/internal/util/util.go b/internal/util/util.go index f7b416f1f..e70e9acee 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -14,6 +14,8 @@ import ( "golang.org/x/text/language" ) +const HOST_COLLECTORS_RUN_AS_ROOT_PROMPT = "Some host collectors need to be run as root.\nDo you want to exit and rerun the command using sudo?" + func HomeDir() string { if h := os.Getenv("HOME"); h != "" { return h diff --git a/pkg/preflight/run.go b/pkg/preflight/run.go index 45a75f056..8b084111d 100644 --- a/pkg/preflight/run.go +++ b/pkg/preflight/run.go @@ -50,7 +50,7 @@ func RunPreflights(interactive bool, output string, format string, args []string if interactive { if len(specs.HostPreflightsV1Beta2) > 0 && !util.IsRunningAsRoot() { fmt.Print(cursor.Show()) - if util.PromptYesNo("Some host collectors may require elevated privileges to run.\nDo you want to exit and rerun the command as a privileged user?") { + if util.PromptYesNo(util.HOST_COLLECTORS_RUN_AS_ROOT_PROMPT) { fmt.Println("Exiting...") return nil }