refactor go-flags initialization
This commit is contained in:
27
main.go
27
main.go
@@ -4,29 +4,22 @@ 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.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"`
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := run(os.Args); err != nil {
|
||||
flags := goflags.NewParser(nil, goflags.Default)
|
||||
|
||||
rootfs := cmdrootfs.NewCommand()
|
||||
lxcconfig := cmdlxcconfig.NewCommand()
|
||||
flags.AddCommand("rootfs", rootfs.ShortDesc(), rootfs.LongDesc(), rootfs)
|
||||
flags.AddCommand("lxcconfig", lxcconfig.ShortDesc(), lxcconfig.LongDesc(), lxcconfig)
|
||||
|
||||
_, err := flags.Parse()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func run(args []string) error {
|
||||
var opts params
|
||||
if _, err := goflags.ParseArgs(&opts, args[1:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user