move command implementations to internal/
This commit is contained in:
parent
02cec0f76f
commit
a9b4f1ecd4
3
BUILD
3
BUILD
@ -6,9 +6,8 @@ go_library(
|
||||
importpath = "github.com/motiejus/code/undocker",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//src/undocker/rootfs:go_default_library",
|
||||
"//src/undocker/internal/cmdrootfs:go_default_library",
|
||||
"@com_github_jessevdk_go_flags//:go_default_library",
|
||||
"@org_uber_go_multierr//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
|
13
internal/cmdrootfs/BUILD
Normal file
13
internal/cmdrootfs/BUILD
Normal file
@ -0,0 +1,13 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["cmdrootfs.go"],
|
||||
importpath = "github.com/motiejus/code/undocker/internal/cmdrootfs",
|
||||
visibility = ["//src/undocker:__subpackages__"],
|
||||
deps = [
|
||||
"//src/undocker/rootfs:go_default_library",
|
||||
"@com_github_jessevdk_go_flags//:go_default_library",
|
||||
"@org_uber_go_multierr//:go_default_library",
|
||||
],
|
||||
)
|
43
internal/cmdrootfs/cmdrootfs.go
Normal file
43
internal/cmdrootfs/cmdrootfs.go
Normal file
@ -0,0 +1,43 @@
|
||||
package cmdrootfs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
goflags "github.com/jessevdk/go-flags"
|
||||
"github.com/motiejus/code/undocker/rootfs"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
type CmdRootFS struct {
|
||||
PositionalArgs struct {
|
||||
Infile goflags.Filename `long:"infile" description:"Input tarball"`
|
||||
Outfile string `long:"outfile" description:"Output path, stdout is '-'"`
|
||||
} `positional-args:"yes" required:"yes"`
|
||||
}
|
||||
|
||||
func (r *CmdRootFS) Execute(args []string) (err 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 func() { err = multierr.Append(err, in.Close()) }()
|
||||
|
||||
var out *os.File
|
||||
outf := string(r.PositionalArgs.Outfile)
|
||||
if outf == "-" {
|
||||
out = os.Stdout
|
||||
} else {
|
||||
out, err = os.Create(outf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer func() { err = multierr.Append(err, out.Close()) }()
|
||||
|
||||
return rootfs.RootFS(in, out)
|
||||
}
|
39
main.go
39
main.go
@ -1,17 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
goflags "github.com/jessevdk/go-flags"
|
||||
"github.com/motiejus/code/undocker/rootfs"
|
||||
"go.uber.org/multierr"
|
||||
"github.com/motiejus/code/undocker/internal/cmdrootfs"
|
||||
)
|
||||
|
||||
type (
|
||||
params struct {
|
||||
RootFS cmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
|
||||
RootFS cmdrootfs.CmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
|
||||
Manifest cmdManifest `command:"manifest"`
|
||||
}
|
||||
|
||||
@ -33,36 +31,3 @@ 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 path, stdout is '-'"`
|
||||
} `positional-args:"yes" required:"yes"`
|
||||
}
|
||||
|
||||
func (r *cmdRootFS) Execute(args []string) (err 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 func() { err = multierr.Append(err, in.Close()) }()
|
||||
|
||||
var out *os.File
|
||||
outf := string(r.PositionalArgs.Outfile)
|
||||
if outf == "-" {
|
||||
out = os.Stdout
|
||||
} else {
|
||||
out, err = os.Create(outf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer func() { err = multierr.Append(err, out.Close()) }()
|
||||
|
||||
return rootfs.RootFS(in, out)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user