cmdlxcconfig
This commit is contained in:
parent
890d99cd3e
commit
a333fb34ef
1
BUILD
1
BUILD
@ -6,6 +6,7 @@ go_library(
|
|||||||
importpath = "github.com/motiejus/code/undocker",
|
importpath = "github.com/motiejus/code/undocker",
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"//src/undocker/internal/cmdlxcconfig:go_default_library",
|
||||||
"//src/undocker/internal/cmdrootfs:go_default_library",
|
"//src/undocker/internal/cmdrootfs:go_default_library",
|
||||||
"@com_github_jessevdk_go_flags//:go_default_library",
|
"@com_github_jessevdk_go_flags//:go_default_library",
|
||||||
],
|
],
|
||||||
|
13
internal/cmdlxcconfig/BUILD
Normal file
13
internal/cmdlxcconfig/BUILD
Normal 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",
|
||||||
|
],
|
||||||
|
)
|
45
internal/cmdlxcconfig/cmdlxcconfig.go
Normal file
45
internal/cmdlxcconfig/cmdlxcconfig.go
Normal 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)
|
||||||
|
}
|
@ -9,28 +9,28 @@ import (
|
|||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdRootFS is "rootfs" command
|
// Command is "rootfs" command
|
||||||
type CmdRootFS struct {
|
type Command struct {
|
||||||
PositionalArgs struct {
|
PositionalArgs struct {
|
||||||
Infile goflags.Filename `long:"infile" description:"Input tarball"`
|
Infile goflags.Filename `long:"infile" description:"Input tarball"`
|
||||||
Outfile string `long:"outfile" description:"Output path, stdout is '-'"`
|
Outfile string `long:"outfile" description:"Output path, stdout is '-'"`
|
||||||
} `positional-args:"yes" required:"yes"`
|
} `positional-args:"yes" required:"yes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute executes CmdRootFS
|
// Execute executes rootfs Command
|
||||||
func (r *CmdRootFS) Execute(args []string) (err error) {
|
func (c *Command) Execute(args []string) (err error) {
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
return errors.New("too many args")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() { err = multierr.Append(err, rd.Close()) }()
|
defer func() { err = multierr.Append(err, rd.Close()) }()
|
||||||
|
|
||||||
var out *os.File
|
var out *os.File
|
||||||
outf := string(r.PositionalArgs.Outfile)
|
outf := string(c.PositionalArgs.Outfile)
|
||||||
if outf == "-" {
|
if outf == "-" {
|
||||||
out = os.Stdout
|
out = os.Stdout
|
||||||
} else {
|
} else {
|
||||||
|
7
main.go
7
main.go
@ -4,16 +4,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
goflags "github.com/jessevdk/go-flags"
|
goflags "github.com/jessevdk/go-flags"
|
||||||
|
"github.com/motiejus/code/undocker/internal/cmdlxcconfig"
|
||||||
"github.com/motiejus/code/undocker/internal/cmdrootfs"
|
"github.com/motiejus/code/undocker/internal/cmdrootfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
params struct {
|
params struct {
|
||||||
RootFS cmdrootfs.CmdRootFS `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
|
RootFS cmdrootfs.Command `command:"rootfs" description:"Unpack a docker container image to a single filesystem tarball"`
|
||||||
Manifest cmdManifest `command:"manifest"`
|
LXCConfig cmdlxcconfig.Command `command:"lxcconfig" description:"Create an LXC-compatible container configuration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdManifest struct{} // stub
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user