From 273c337a238a2bf09e6dfd2755731f4ed0aab076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 24 May 2021 00:11:57 +0300 Subject: [PATCH] move rootfs, add gofmt --- BUILD | 5 ++++- main.go | 28 +++++++++++----------------- rootfs.go | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 rootfs.go diff --git a/BUILD b/BUILD index bd10e1f..c10f473 100644 --- a/BUILD +++ b/BUILD @@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") go_library( name = "undocker_lib", - srcs = ["main.go"], + srcs = [ + "main.go", + "rootfs.go", + ], importpath = "github.com/motiejus/code/undocker", visibility = ["//visibility:private"], deps = ["@com_github_jessevdk_go_flags//:go-flags"], diff --git a/main.go b/main.go index 36ade5a..1a6250c 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,20 @@ package main import ( - "fmt" "os" - "errors" goflags "github.com/jessevdk/go-flags" ) -type opts struct { - PositionalArgs struct { - Infile goflags.Filename `long:"infile" description:"Docker container tarball"` - Outfile string `long:"outfile" description:"Output tarball"` - } `positional-args:"yes" required:"yes"` -} +type ( + params struct { + RootFS cmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"` + Manifest cmdManifest `command:"manifest"` + } + + cmdManifest struct{} // stub + +) func main() { if err := run(os.Args); err != nil { @@ -23,17 +24,10 @@ func main() { } func run(args []string) error { - var flags opts - args1, err := goflags.ParseArgs(&flags, args) - if err != nil { + var opts params + if _, err := goflags.ParseArgs(&opts, args[1:]); err != nil { return err } - if len(args1) != 0 { - return errors.New("too many args") - } - - fmt.Printf("infile: %s\n", flags.PositionalArgs.Infile) - fmt.Printf("outfile: %s\n", flags.PositionalArgs.Outfile) return nil } diff --git a/rootfs.go b/rootfs.go new file mode 100644 index 0000000..03f1efd --- /dev/null +++ b/rootfs.go @@ -0,0 +1,21 @@ +package main + +import ( + "errors" + + goflags "github.com/jessevdk/go-flags" +) + +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") + } + return nil +}