move rootfs, add gofmt

This commit is contained in:
Motiejus Jakštys 2021-05-24 00:11:57 +03:00
parent 0f883d49e7
commit 273c337a23
3 changed files with 36 additions and 18 deletions

5
BUILD
View File

@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library( go_library(
name = "undocker_lib", name = "undocker_lib",
srcs = ["main.go"], srcs = [
"main.go",
"rootfs.go",
],
importpath = "github.com/motiejus/code/undocker", importpath = "github.com/motiejus/code/undocker",
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
deps = ["@com_github_jessevdk_go_flags//:go-flags"], deps = ["@com_github_jessevdk_go_flags//:go-flags"],

28
main.go
View File

@ -1,19 +1,20 @@
package main package main
import ( import (
"fmt"
"os" "os"
"errors"
goflags "github.com/jessevdk/go-flags" goflags "github.com/jessevdk/go-flags"
) )
type opts struct { type (
PositionalArgs struct { params struct {
Infile goflags.Filename `long:"infile" description:"Docker container tarball"` RootFS cmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
Outfile string `long:"outfile" description:"Output tarball"` Manifest cmdManifest `command:"manifest"`
} `positional-args:"yes" required:"yes"` }
}
cmdManifest struct{} // stub
)
func main() { func main() {
if err := run(os.Args); err != nil { if err := run(os.Args); err != nil {
@ -23,17 +24,10 @@ func main() {
} }
func run(args []string) error { func run(args []string) error {
var flags opts var opts params
args1, err := goflags.ParseArgs(&flags, args) if _, err := goflags.ParseArgs(&opts, args[1:]); err != nil {
if err != nil {
return err 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 return nil
} }

21
rootfs.go Normal file
View File

@ -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
}