This commit is contained in:
Motiejus Jakštys 2021-05-24 00:11:58 +03:00
parent 7e55ae4ca5
commit 5ab9a5bc3a
4 changed files with 43 additions and 4 deletions

1
BUILD
View File

@ -9,6 +9,7 @@ go_library(
visibility = ["//visibility:private"], visibility = ["//visibility:private"],
deps = [ deps = [
"//src/undocker/internal/cmdlxcconfig:go_default_library", "//src/undocker/internal/cmdlxcconfig:go_default_library",
"//src/undocker/internal/cmdmanpage: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",
], ],

View File

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

View File

@ -0,0 +1,25 @@
package cmdmanpage
import (
"io"
"os"
goflags "github.com/jessevdk/go-flags"
)
type Command struct {
parser *goflags.Parser
stdout io.Writer
}
func NewCommand(parser *goflags.Parser) *Command {
return &Command{
parser: parser,
stdout: os.Stdout,
}
}
func (c *Command) Execute(args []string) error {
c.parser.WriteManPage(c.stdout)
return nil
}

12
main.go
View File

@ -5,18 +5,22 @@ import (
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/cmdlxcconfig"
"github.com/motiejus/code/undocker/internal/cmdmanpage"
"github.com/motiejus/code/undocker/internal/cmdrootfs" "github.com/motiejus/code/undocker/internal/cmdrootfs"
) )
func main() { func main() {
flags := goflags.NewParser(nil, goflags.Default) parser := goflags.NewParser(nil, goflags.Default)
rootfs := cmdrootfs.NewCommand() rootfs := cmdrootfs.NewCommand()
lxcconfig := cmdlxcconfig.NewCommand() lxcconfig := cmdlxcconfig.NewCommand()
flags.AddCommand("rootfs", rootfs.ShortDesc(), rootfs.LongDesc(), rootfs) manpage := cmdmanpage.NewCommand(parser)
flags.AddCommand("lxcconfig", lxcconfig.ShortDesc(), lxcconfig.LongDesc(), lxcconfig) parser.AddCommand("rootfs", rootfs.ShortDesc(), rootfs.LongDesc(), rootfs)
parser.AddCommand("lxcconfig", lxcconfig.ShortDesc(), lxcconfig.LongDesc(), lxcconfig)
m, _ := parser.AddCommand("man-page", "", "", manpage)
m.Hidden = true
_, err := flags.Parse() _, err := parser.Parse()
if err != nil { if err != nil {
os.Exit(1) os.Exit(1)
} }