1
Fork 0

cmdlxcconfig

main
Motiejus Jakštys 2021-05-24 00:11:58 +03:00
parent 890d99cd3e
commit a333fb34ef
5 changed files with 68 additions and 10 deletions

1
BUILD
View File

@ -6,6 +6,7 @@ go_library(
importpath = "github.com/motiejus/code/undocker",
visibility = ["//visibility:private"],
deps = [
"//src/undocker/internal/cmdlxcconfig:go_default_library",
"//src/undocker/internal/cmdrootfs:go_default_library",
"@com_github_jessevdk_go_flags//:go_default_library",
],

View File

@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["cmdlxcconfig.go"],
importpath = "github.com/motiejus/code/undocker/internal/cmdlxcconfig",
visibility = ["//src/undocker:__subpackages__"],
deps = [
"//src/undocker/lxcconfig:go_default_library",
"@com_github_jessevdk_go_flags//:go_default_library",
"@org_uber_go_multierr//:go_default_library",
],
)

View File

@ -0,0 +1,45 @@
package cmdlxcconfig
import (
"errors"
"os"
goflags "github.com/jessevdk/go-flags"
"github.com/motiejus/code/undocker/lxcconfig"
"go.uber.org/multierr"
)
// Command is "lxcconfig" command
type Command 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"`
}
// Execute executes lxcconfig Command
func (c *Command) Execute(args []string) (err error) {
if len(args) != 0 {
return errors.New("too many args")
}
rd, err := os.Open(string(c.PositionalArgs.Infile))
if err != nil {
return err
}
defer func() { err = multierr.Append(err, rd.Close()) }()
var out *os.File
outf := string(c.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 lxcconfig.LXCConfig(rd, out)
}

View File

@ -9,28 +9,28 @@ import (
"go.uber.org/multierr"
)
// CmdRootFS is "rootfs" command
type CmdRootFS struct {
// Command is "rootfs" command
type Command 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"`
}
// Execute executes CmdRootFS
func (r *CmdRootFS) Execute(args []string) (err error) {
// Execute executes rootfs Command
func (c *Command) Execute(args []string) (err error) {
if len(args) != 0 {
return errors.New("too many args")
}
rd, err := os.Open(string(r.PositionalArgs.Infile))
rd, err := os.Open(string(c.PositionalArgs.Infile))
if err != nil {
return err
}
defer func() { err = multierr.Append(err, rd.Close()) }()
var out *os.File
outf := string(r.PositionalArgs.Outfile)
outf := string(c.PositionalArgs.Outfile)
if outf == "-" {
out = os.Stdout
} else {

View File

@ -4,16 +4,15 @@ import (
"os"
goflags "github.com/jessevdk/go-flags"
"github.com/motiejus/code/undocker/internal/cmdlxcconfig"
"github.com/motiejus/code/undocker/internal/cmdrootfs"
)
type (
params struct {
RootFS cmdrootfs.CmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
Manifest cmdManifest `command:"manifest"`
RootFS cmdrootfs.Command `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
LXCConfig cmdlxcconfig.Command `command:"lxcconfig" description:"Create an LXC-compatible container configuration"`
}
cmdManifest struct{} // stub
)
func main() {