Support reading from standard input in pembody.

This commit is contained in:
Kyle Isom 2016-04-28 14:15:35 -07:00
parent f7bc97405a
commit 4b9da3632a
2 changed files with 12 additions and 2 deletions

View File

@ -1,7 +1,8 @@
pembody pembody
This is a utility for decoding PEM-encoded files and spewing their 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: Example:
$ cat file.pem $ cat file.pem

View File

@ -5,6 +5,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"github.com/kisom/goutils/lib" "github.com/kisom/goutils/lib"
) )
@ -15,7 +16,15 @@ func main() {
lib.Errx(lib.ExitFailure, "a single filename is required") 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 { if err != nil {
lib.Err(lib.ExitFailure, err, "couldn't read file") lib.Err(lib.ExitFailure, err, "couldn't read file")
} }