From 7ab46f740261296e4372bc303d51f4bd41927162 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Tue, 4 Jun 2024 15:09:57 -0400 Subject: [PATCH] Add initial support for reading stdin from the server binary --- libmuttonserver.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libmuttonserver.go b/libmuttonserver.go index 719387d..52fc178 100644 --- a/libmuttonserver.go +++ b/libmuttonserver.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "fmt" "github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/cli" @@ -16,6 +17,19 @@ func main() { helpServer() } + // check if stdin was provided + stdinInfo, _ := os.Stdin.Stat() + stdinPresent := stdinInfo.Mode()&os.ModeNamedPipe != 0 + + var stdin []string + if stdinPresent { + // read stdin, appending each line to the stdin slice + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + stdin = append(stdin, scanner.Text()) + } + } + switch args[1] { case "fetch": // print all information needed for syncing to stdout for interpretation by the client