From 4b9da3632a2314eab691e7841182fa210f096d0f Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 28 Apr 2016 14:15:35 -0700 Subject: [PATCH] Support reading from standard input in pembody. --- cmd/pembody/README | 3 ++- cmd/pembody/pembody.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/pembody/README b/cmd/pembody/README index 90a686e..2f2e612 100644 --- a/cmd/pembody/README +++ b/cmd/pembody/README @@ -1,7 +1,8 @@ pembody This is a utility for decoding PEM-encoded files and spewing their -contents to standard output. No trailing newline is appended. +contents to standard output. No trailing newline is appended. If +the filename is "-", pembody reads from standard input. Example: $ cat file.pem diff --git a/cmd/pembody/pembody.go b/cmd/pembody/pembody.go index e8ed7e4..08802a2 100644 --- a/cmd/pembody/pembody.go +++ b/cmd/pembody/pembody.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "io/ioutil" + "os" "github.com/kisom/goutils/lib" ) @@ -15,7 +16,15 @@ func main() { lib.Errx(lib.ExitFailure, "a single filename is required") } - in, err := ioutil.ReadFile(flag.Arg(0)) + var in []byte + var err error + + path := flag.Arg(0) + if path == "-" { + in, err = ioutil.ReadAll(os.Stdin) + } else { + in, err = ioutil.ReadFile(flag.Arg(0)) + } if err != nil { lib.Err(lib.ExitFailure, err, "couldn't read file") }