commit 273c337a238a2bf09e6dfd2755731f4ed0aab076 (tree)
parent 0f883d49e7f686b7c1074c64b4f4da16968176e3
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Mon, 24 May 2021 00:11:57 +0300
move rootfs, add gofmt
Diffstat:
3 files changed, 36 insertions(+), 18 deletions(-)
diff --git 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
@@ -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
@@ -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
+}