~bayindirh/nudge

0035d0d7010df740f52f790b576dbefbd0cb86fb — Hakan Bayindir 7 months ago 086c4b0
refactor: General polishing run.

- refactor: Correct applyFlags function's signature.
- fix: Correct fmt strings to prevent panics and bad output.
2 files changed, 7 insertions(+), 5 deletions(-)

M CHANGELOG.md
M src/nudge.go
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 5,6 5,8 @@
## 2023-07-26

- fix: Correct a small debug log line to print prettier.
- refactor: Correct `applyFlags` function's signature.
- fix: Correct `fmt` strings to prevent panics and bad output.

## 2023-07-25


M src/nudge.go => src/nudge.go +5 -5
@@ 243,11 243,11 @@ func initFlags(notificationToSend *Notification, flagStorage *FlagStorage, logge
}

// This function simply copies relevant flags to runtime configuration and notification to send.
func applyFlags(setFlags *[]string, flagStorage *FlagStorage, runtimeConfiguration *RuntimeConfiguration, notificationToSend *Notification, logger zap.SugaredLogger) {
func applyFlags(setFlags *[]string, flagStorage *FlagStorage, runtimeConfiguration *RuntimeConfiguration, notificationToSend *Notification, logger *zap.SugaredLogger) {
	// TODO: Revise this function and add proper comments.
	logger.Debugf("Starting to apply flags to runtime configuration.")
	// This is left as a check, to see whether we can approach flag module globally.
	logger.Debugf("Flag parse status is %s.", flag.Parsed())
	logger.Debugf("Flag parse status is %t.", flag.Parsed())

	logger.Debugf("The set flags are %s.", *setFlags)



@@ 275,7 275,7 @@ func applyFlags(setFlags *[]string, flagStorage *FlagStorage, runtimeConfigurati
			logger.Debugf("Notification attached URL will be shown as %s.", notificationToSend.urlTitle)
		case "dryrun":
			runtimeConfiguration.dryrun = flagStorage.dryrun
			logger.Debugf("Dry run mode is set to %s.", runtimeConfiguration.dryrun)
			logger.Debugf("Dry run mode is set to %t.", runtimeConfiguration.dryrun)
		case "log_level":
			runtimeConfiguration.logLevel = flagStorage.logLevel
			logger.Debugf("Logging level is set to %s.", runtimeConfiguration.logLevel)


@@ 344,7 344,7 @@ func printState(runtimeConfiguration *RuntimeConfiguration, notification *Notifi
	// Dump notification in a different block.
	logger.Infof("Notification details")
	logger.Infof("--------------------")
	logger.Info("Recipients: %s", notification.device)
	logger.Infof("Recipients: %s", notification.device)
	logger.Infof("Priority: %d", notification.priority)
	logger.Infof("Sound: %s", notification.sound)
	logger.Infof("Timestamp: %d", notification.timestamp)


@@ 446,7 446,7 @@ func main() {
	})

	// Then I can apply the set flags.
	applyFlags(&setFlags, &flagStorage, &runtimeConfiguration, &notificationToSend, *sugaredLogger)
	applyFlags(&setFlags, &flagStorage, &runtimeConfiguration, &notificationToSend, sugaredLogger)

	// Check whether our version is asked or not.
	// Version info shall always return clean.