From 5da56599575b1d50d50d57f8a1b077f644dcb36c Mon Sep 17 00:00:00 2001 From: Aaron Johnon Date: Mon, 2 Sep 2024 03:04:08 -0500 Subject: [PATCH] Added code to display help if no input is provided via stdin --- nsdecode.go | 7 +++++++ nsencode.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/nsdecode.go b/nsdecode.go index fd6f04e..6be5c9a 100644 --- a/nsdecode.go +++ b/nsdecode.go @@ -49,6 +49,13 @@ func main() { flag.Parse() + // Check if there is input from stdin + info, _ := os.Stdin.Stat() + if (info.Mode() & os.ModeCharDevice) != 0 { + flag.Usage() + os.Exit(1) + } + // Read all input from stdin reader := bufio.NewReader(os.Stdin) inputBytes, _ := io.ReadAll(reader) diff --git a/nsencode.go b/nsencode.go index 359b36a..531c375 100644 --- a/nsencode.go +++ b/nsencode.go @@ -99,6 +99,13 @@ func main() { flag.Parse() + // Check if there is input from stdin + info, _ := os.Stdin.Stat() + if (info.Mode() & os.ModeCharDevice) != 0 { + flag.Usage() + os.Exit(1) + } + // Read input from stdin reader := bufio.NewReader(os.Stdin) input, _ := reader.ReadString('\n')