Skip to content

Commit

Permalink
Convert remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Nov 21, 2024
1 parent 6a801e8 commit e091792
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/state-svc/internal/notifications/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func conditionFuncMap() template.FuncMap {
"regexMatch": func(str, pattern string) bool {
rx, err := regexp.Compile(pattern)
if err != nil {
multilog.Error("Messages: Could not compile regex pattern: %s", err)
multilog.Error("Notifications: Could not compile regex pattern: %s", err)
return false
}
return rx.MatchString(str)
Expand Down
10 changes: 5 additions & 5 deletions cmd/state-svc/internal/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/blang/semver"
)

const ConfigKeyLastReport = "messages.last_reported"
const ConfigKeyLastReport = "notifications.last_reported"

type Notifications struct {
cfg *config.Instance
Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *Notifications) Check(command string, flags []string) ([]*graph.Notifica
lastReportMap := m.cfg.GetStringMap(ConfigKeyLastReport)
msgs, err := check(&conditionParams, allNotifications, lastReportMap, time.Now())
if err != nil {
return nil, errs.Wrap(err, "Could not check messages")
return nil, errs.Wrap(err, "Could not check notifications")
}
for _, msg := range msgs {
lastReportMap[msg.ID] = time.Now().Format(time.RFC3339)
Expand Down Expand Up @@ -205,18 +205,18 @@ func fetch() ([]*graph.NotificationInfo, error) {
if v := os.Getenv(constants.NotificationsOverrideEnvVarName); v != "" {
body, err = fileutils.ReadFile(v)
if err != nil {
return nil, errs.Wrap(err, "Could not read messages override file")
return nil, errs.Wrap(err, "Could not read notifications override file")
}
} else {
body, err = httputil.Get(constants.NotificationsInfoURL)
if err != nil {
return nil, errs.Wrap(err, "Could not fetch messages information")
return nil, errs.Wrap(err, "Could not fetch notifications information")
}
}

var notifications []*graph.NotificationInfo
if err := json.Unmarshal(body, &notifications); err != nil {
return nil, errs.Wrap(err, "Could not unmarshall messages information")
return nil, errs.Wrap(err, "Could not unmarshall notifications information")
}

// Set defaults
Expand Down
20 changes: 10 additions & 10 deletions cmd/state/internal/cmdtree/exechandlers/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func New(out output.Outputer, svcModel *model.SvcModel) *Notifier {

func (m *Notifier) OnExecStart(cmd *captain.Command, _ []string) error {
if m.out.Type().IsStructured() {
// No point showing messaging on non-plain output (eg. json)
// No point showing notifications on non-plain output (eg. json)
return nil
}

if cmd.Name() == "update" {
return nil // do not print update/deprecation warnings/messages when running `state update`
return nil // do not print update/deprecation warnings/notifications when running `state update`
}

cmds := cmd.JoinedCommandNames()
Expand All @@ -52,24 +52,24 @@ func (m *Notifier) OnExecStart(cmd *captain.Command, _ []string) error {
logging.Debug("Received %d notifications to print", len(notifications))

if err := m.PrintByPlacement(graph.NotificationPlacementTypeBeforeCmd); err != nil {
return errs.Wrap(err, "message error occurred before cmd")
return errs.Wrap(err, "notification error occurred before cmd")
}

return nil
}

func (m *Notifier) OnExecStop(cmd *captain.Command, _ []string) error {
if m.out.Type().IsStructured() {
// No point showing messaging on non-plain output (eg. json)
// No point showing notification on non-plain output (eg. json)
return nil
}

if cmd.Name() == "update" {
return nil // do not print update/deprecation warnings/messages when running `state update`
return nil // do not print update/deprecation warnings/notifications when running `state update`
}

if err := m.PrintByPlacement(graph.NotificationPlacementTypeAfterCmd); err != nil {
return errs.Wrap(err, "message error occurred before cmd")
return errs.Wrap(err, "notification error occurred before cmd")
}

return nil
Expand Down Expand Up @@ -99,10 +99,10 @@ func (m *Notifier) PrintByPlacement(placement graph.NotificationPlacementType) e

if notification.Interrupt == graph.NotificationInterruptTypePrompt {
if m.out.Config().Interactive {
m.out.Print(locale.Tl("messenger_prompt_continue", "Press ENTER to continue."))
m.out.Print(locale.Tl("notifier_prompt_continue", "Press ENTER to continue."))
fmt.Scanln(ptr.To("")) // Wait for input from user
} else {
logging.Debug("Skipping message prompt as we're not in interactive mode")
logging.Debug("Skipping notification prompt as we're not in interactive mode")
}
}

Expand All @@ -114,9 +114,9 @@ func (m *Notifier) PrintByPlacement(placement graph.NotificationPlacementType) e
m.notifications = notifications

if len(exit) > 0 {
// It's the responsibility of the message to give the user context as to why this exit happened.
// It's the responsibility of the notification to give the user context as to why this exit happened.
// We pass an input error here to ensure this doesn't get logged.
return errs.Silence(errs.WrapExitCode(errs.New("Following messages triggered exit: %s", strings.Join(exit, ", ")), 1))
return errs.Silence(errs.WrapExitCode(errs.New("Following notifications triggered exit: %s", strings.Join(exit, ", ")), 1))
}

return nil
Expand Down

0 comments on commit e091792

Please sign in to comment.