Skip to content

Commit

Permalink
chore: Update CLI prompt to run command as root (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh authored Mar 28, 2024
1 parent ca5ff88 commit c9830de
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/preflight/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c9830de

Please sign in to comment.