~bayindirh/nudge

2d5e04ca3a341be6d887fdd0288f412a0b8aaeff — Hakan Bayindir 4 months ago ca7fb15
refactor: Polish the code base a little.

- refactor: Make some warning messages' format more uniform.
- refactor: Unified how error meessages are implemented.
- refactor: Add more logging in initFlags function.
2 files changed, 12 insertions(+), 5 deletions(-)

M CHANGELOG.md
M src/nudge.go
M CHANGELOG.md => CHANGELOG.md +6 -0
@@ 2,6 2,12 @@

**Note:** Please add newest entries on top. Use ISO date format YYYY-MM-DD and markdown formatting.

## 2023-11-15
- refactor: Make some warning messages' format more uniform.
- refactor: Unified how error meessages are implemented.
- refactor: Add more logging in `initFlags` function.


## 2023-11-14
- refactor: Change HTML variable from `int` to `bool`.
- feat: Implement HTML message sending support.

M src/nudge.go => src/nudge.go +6 -5
@@ 108,7 108,7 @@ func isInputFromPipe(logger *zap.SugaredLogger) bool {

	// Check whether things have worked out.
	if err != nil {
		logger.Fatalf("Cannot stat stdin, exiting (error is %s)", err.Error())
		logger.Panicf("Cannot stat stdin, exiting (error is %s)", err)
	}

	// Let's check whether our stdin is a character device or not.


@@ 185,14 185,14 @@ func readAndApplyConfiguration(configurationFilePath *string, runtimeConfigurati
		userConfigDirectory, err := os.UserConfigDir()

		if err != nil {
			logger.Panicf("Error getting user's config directory, exiting (error is %s).", err.Error())
			logger.Panicf("Error getting user's config directory, exiting (error is %s).", err)
		}

		workingDirectory, err := os.Getwd()
		logger.Debugf("Current directory is %s", workingDirectory)

		if err != nil {
			logger.Panicf("Error getting working directory, exiting (error is %s).", err.Error())
			logger.Panicf("Error getting working directory, exiting (error is %s).", err)
		}

		// The logic is to allow user to override local config with a test config.


@@ 210,7 210,7 @@ func readAndApplyConfiguration(configurationFilePath *string, runtimeConfigurati
	// Handle errors reading the config file.
	// Do not create warnings here, all config warnings are handled by checkConfigurationSanity() function.
	if err != nil {
		logger.Debugf("Cannot find any configuration file, continuing using built-in defaults (%s).", err.Error())
		logger.Debugf("Cannot find any configuration file, continuing using built-in defaults (%s).", err)
	} else {
		// If we've reached here, we can take note of the file path now.
		// This also means that we have read the config file successfully.


@@ 268,6 268,7 @@ func initFlags(notificationToSend *Notification, runtimeConfiguration *RuntimeCo
	// Otherwise, we leave the message empty. The check in the main() will
	// handle the error condition.
	if isInputFromPipe(logger) == false && flag.NArg() == 1 {
		logger.Debugf("Program is called directly, and we have a single argument, so using it as the message body.")
		notificationToSend.messageBody = flag.Arg(0)
	}



@@ 329,7 330,7 @@ func applyFlags(setFlags *[]string, flagStorage *FlagStorage, runtimeConfigurati
		case "version":
			logger.Debugf("Ignoring flag %s. Handled elsewhere.", flagValue)
		default:
			logger.Warnf("Unhandled flag %s. Ignoring.", flagValue)
			logger.Warnf("Ignoring flag %s. Unhandled.", flagValue)
		}
	}
	// Skipped configPath, because it's handled in readAndApplyConfiguration.