70c244a00acce78daa2cb5b9b5f4cdf0af6dc21a — Hakan Bayindir 2 months ago 2d5e04c
feat: Implement preliminary Unix pipe support.

feat: Implement preliminary Unix pipe support. It can be used to send single line messages. Multiline messages will be implemented next.
2 files changed, 18 insertions(+), 0 deletions(-)

M src/nudge.go
@@ 2,6 2,9 @@

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

## 2023-11-30
- feat: Implement initial version of Unix pipe support. Feature development is in progress.

## 2023-11-15
- refactor: Make some warning messages' format more uniform.
- refactor: Unified how error meessages are implemented.

M src/nudge.go => src/nudge.go +15 -0
@@ 270,6 270,21 @@ func initFlags(notificationToSend *Notification, runtimeConfiguration *RuntimeCo
	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)
	} else if isInputFromPipe(logger) == true {
		// If we're operating under pipe mode, Stdin is still available to us.
		logger.Warnf("Pipe support is under development, and not completed yet. Use at your own risk.")
		messageSize, err := fmt.Scanln(&notificationToSend.messageBody)
		if err != nil {
			if err.Error() == "unexpected newline" {
				logger.Debugf("%s is encountered, and possibly the message is empty. Continuing.")
			} else {
				logger.Panicf("Something went wrong while getting the message from the pipe (Error is %s)", err)
		logger.Debugf("Got a message with length of %d.", messageSize)
		flagStorage.dryrun = true

	// Print how many arguments we got, as a debug message. flag.Narg() returns the number