Skip to content

Commit

Permalink
fix: Do not use non-constant format string with Printf/Errorf
Browse files Browse the repository at this point in the history
* Fix some code style issues and make code linter more happy
  • Loading branch information
jirihnidek authored and subpop committed Sep 4, 2024
1 parent 124b388 commit 87c37da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
39 changes: 21 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,20 @@ func connectAction(ctx *cli.Context) error {
message: fmt.Errorf("cannot connect to Red Hat Subscription Management: %w",
err)}
fmt.Printf(
uiSettings.iconError + " Cannot connect to Red Hat Subscription Management\n",
"%v Cannot connect to Red Hat Subscription Management\n",
uiSettings.iconError,
)
} else {
fmt.Printf(uiSettings.iconOK + " " + returnedMsg + "\n")
fmt.Printf("%v %v\n", uiSettings.iconOK, returnedMsg)
}
durations["rhsm"] = time.Since(start)

/* 2. Register insights-client */
if errors, exist := errorMessages["rhsm"]; exist {
if errors.level == log.LevelError {
fmt.Printf(
uiSettings.iconError + " Skipping connection to Red Hat Insights\n",
"%v Skipping connection to Red Hat Insights\n",
uiSettings.iconError,
)
}
} else {
Expand All @@ -320,9 +322,9 @@ func connectAction(ctx *cli.Context) error {
level: log.LevelError,
message: fmt.Errorf("cannot connect to Red Hat Insights: %w",
err)}
fmt.Printf(uiSettings.iconError + " Cannot connect to Red Hat Insights\n")
fmt.Printf("%v Cannot connect to Red Hat Insights\n", uiSettings.iconError)
} else {
fmt.Printf(uiSettings.iconOK + " Connected to Red Hat Insights\n")
fmt.Printf("%v Connected to Red Hat Insights\n", uiSettings.iconOK)
}
durations["insights"] = time.Since(start)
}
Expand All @@ -331,7 +333,8 @@ func connectAction(ctx *cli.Context) error {
if errors, exist := errorMessages["rhsm"]; exist {
if errors.level == log.LevelError {
fmt.Printf(
uiSettings.iconError+" Skipping activation of %v service\n",
"%v Skipping activation of %v service\n",
uiSettings.iconError,
ServiceName,
)
}
Expand All @@ -344,9 +347,9 @@ func connectAction(ctx *cli.Context) error {
level: log.LevelError,
message: fmt.Errorf("cannot activate %s service: %w",
ServiceName, err)}
fmt.Printf(uiSettings.iconError+" Cannot activate the %v service\n", ServiceName)
fmt.Printf("%v Cannot activate the %v service\n", uiSettings.iconError, ServiceName)
} else {
fmt.Printf(uiSettings.iconOK+" Activated the %v service\n", ServiceName)
fmt.Printf("%v Activated the %v service\n", uiSettings.iconOK, ServiceName)
}
durations[ServiceName] = time.Since(start)
}
Expand Down Expand Up @@ -379,7 +382,7 @@ func connectAction(ctx *cli.Context) error {
message: fmt.Errorf("cannot get the user profile: %w",
err)}
} else {
fmt.Printf(uiSettings.iconInfo + " Enabled console.redhat.com services: ")
fmt.Printf("%v Enabled console.redhat.com services: ", uiSettings.iconInfo)
showConfProfile(&profile)
fmt.Printf("\n")
}
Expand Down Expand Up @@ -517,13 +520,13 @@ func disconnectAction(ctx *cli.Context) error {
errMsg := fmt.Sprintf("Cannot deactivate %s service: %v", ServiceName, err)
errorMessages[ServiceName] = LogMessage{
level: log.LevelError,
message: fmt.Errorf(errMsg)}
message: fmt.Errorf("%v", errMsg)}
disconnectResult.YggdrasilStopped = false
disconnectResult.YggdrasilStoppedError = errMsg
interactivePrintf(uiSettings.iconError + " " + errMsg + "\n")
interactivePrintf("%v %v\n", uiSettings.iconError, errMsg)
} else {
disconnectResult.YggdrasilStopped = true
interactivePrintf(uiSettings.iconOK+" Deactivated the %v service\n", ServiceName)
interactivePrintf("%v Deactivated the %v service\n", uiSettings.iconOK, ServiceName)
}
durations[ServiceName] = time.Since(start)

Expand All @@ -534,13 +537,13 @@ func disconnectAction(ctx *cli.Context) error {
errMsg := fmt.Sprintf("Cannot disconnect from Red Hat Insights: %v", err)
errorMessages["insights"] = LogMessage{
level: log.LevelError,
message: fmt.Errorf(errMsg)}
message: fmt.Errorf("%v", errMsg)}
disconnectResult.InsightsDisconnected = false
disconnectResult.InsightsDisconnectedError = errMsg
interactivePrintf(uiSettings.iconError + " " + errMsg + "\n")
interactivePrintf("%v %v\n", uiSettings.iconError, errMsg)
} else {
disconnectResult.InsightsDisconnected = true
interactivePrintf(uiSettings.iconOK + " Disconnected from Red Hat Insights\n")
interactivePrintf("%v Disconnected from Red Hat Insights\n", uiSettings.iconOK)
}
durations["insights"] = time.Since(start)

Expand All @@ -552,14 +555,14 @@ func disconnectAction(ctx *cli.Context) error {
errMsg := fmt.Sprintf("Cannot disconnect from Red Hat Subscription Management: %v", err)
errorMessages["rhsm"] = LogMessage{
level: log.LevelError,
message: fmt.Errorf(errMsg)}
message: fmt.Errorf("%v", errMsg)}

disconnectResult.RHSMDisconnected = false
disconnectResult.RHSMDisconnectedError = errMsg
interactivePrintf(uiSettings.iconError + " " + errMsg + "\n")
interactivePrintf("%v %v\n", uiSettings.iconError, errMsg)
} else {
disconnectResult.RHSMDisconnected = true
interactivePrintf(uiSettings.iconOK + " Disconnected from Red Hat Subscription Management\n")
interactivePrintf("%v Disconnected from Red Hat Subscription Management\n", uiSettings.iconOK)
}
durations["rhsm"] = time.Since(start)

Expand Down
4 changes: 2 additions & 2 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func rhsmStatus(systemStatus *SystemStatus) error {
if uiSettings.isMachineReadable {
systemStatus.RHSMConnected = false
} else {
fmt.Printf(uiSettings.iconInfo + " Not connected to Red Hat Subscription Management\n")
fmt.Printf("%v Not connected to Red Hat Subscription Management\n", uiSettings.iconInfo)
}
} else {
if uiSettings.isMachineReadable {
systemStatus.RHSMConnected = true
} else {
fmt.Printf(uiSettings.iconOK + " Connected to Red Hat Subscription Management\n")
fmt.Printf("%v Connected to Red Hat Subscription Management\n", uiSettings.iconOK)
}
}
return nil
Expand Down

0 comments on commit 87c37da

Please sign in to comment.