move rootfs to its own package

This commit is contained in:
2021-05-24 00:11:57 +03:00
parent ce445b19b7
commit 3279b52973
4 changed files with 44 additions and 39 deletions

28
main.go
View File

@@ -1,9 +1,11 @@
package main
import (
"errors"
"os"
goflags "github.com/jessevdk/go-flags"
"github.com/motiejus/code/undocker/rootfs"
)
type (
@@ -31,3 +33,29 @@ func run(args []string) error {
return nil
}
type cmdRootFS struct {
PositionalArgs struct {
Infile goflags.Filename `long:"infile" description:"Input tarball"`
Outfile string `long:"outfile" description:"Output tarball (flattened file system)"`
} `positional-args:"yes" required:"yes"`
}
func (r *cmdRootFS) Execute(args []string) error {
if len(args) != 0 {
return errors.New("too many args")
}
in, err := os.Open(string(r.PositionalArgs.Infile))
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(string(r.PositionalArgs.Outfile))
if err != nil {
return err
}
defer out.Close()
return rootfs.Rootfs(in, out)
}