stdout is -
This commit is contained in:
parent
f9eea46417
commit
ce8ce9f59e
10
main.go
10
main.go
@ -37,7 +37,7 @@ func run(args []string) error {
|
|||||||
type cmdRootFS struct {
|
type cmdRootFS struct {
|
||||||
PositionalArgs struct {
|
PositionalArgs struct {
|
||||||
Infile goflags.Filename `long:"infile" description:"Input tarball"`
|
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"`
|
} `positional-args:"yes" required:"yes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,10 +54,16 @@ func (r *cmdRootFS) Execute(args []string) (err error) {
|
|||||||
err = multierr.Append(err, in.Close())
|
err = multierr.Append(err, in.Close())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
out, err := os.Create(string(r.PositionalArgs.Outfile))
|
var out *os.File
|
||||||
|
outf := string(r.PositionalArgs.Outfile)
|
||||||
|
if outf == "-" {
|
||||||
|
out = os.Stdout
|
||||||
|
} else {
|
||||||
|
out, err = os.Create(outf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err = multierr.Append(err, out.Close())
|
err = multierr.Append(err, out.Close())
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user