From ce8ce9f59edeb0eaa2390dd3f18727d02e721318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 24 May 2021 00:11:58 +0300 Subject: [PATCH] stdout is - --- main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1262af6..9fe7281 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ func run(args []string) error { type cmdRootFS struct { PositionalArgs struct { Infile goflags.Filename `long:"infile" description:"Input tarball"` - Outfile string `long:"outfile" description:"Output tarball (flattened file system)"` + Outfile string `long:"outfile" description:"Output path, stdout is '-'"` } `positional-args:"yes" required:"yes"` } @@ -54,9 +54,15 @@ func (r *cmdRootFS) Execute(args []string) (err error) { err = multierr.Append(err, in.Close()) }() - out, err := os.Create(string(r.PositionalArgs.Outfile)) - if err != nil { - return err + var out *os.File + outf := string(r.PositionalArgs.Outfile) + if outf == "-" { + out = os.Stdout + } else { + out, err = os.Create(outf) + if err != nil { + return err + } } defer func() { err = multierr.Append(err, out.Close())