From 94866656a4e48ee5a09f26493e7d6affc1303653 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 2 Mar 2023 11:01:11 +0100 Subject: [PATCH] generate man pages via sub command Signed-off-by: Christian Goll --- Makefile | 18 ++++----------- cmd/bash_completion/bash_completion.go | 23 ------------------- cmd/man_page/man_page.go | 17 -------------- .../app/wwctl/genconf/completions/main.go | 10 ++++---- internal/app/wwctl/genconf/man/main.go | 15 ++++++++++++ internal/app/wwctl/genconf/man/root.go | 23 +++++++++++++++++++ internal/app/wwctl/genconf/root.go | 5 +++- internal/app/wwctl/root.go | 19 --------------- 8 files changed, 52 insertions(+), 78 deletions(-) delete mode 100644 cmd/bash_completion/bash_completion.go delete mode 100644 cmd/man_page/man_page.go create mode 100644 internal/app/wwctl/genconf/man/main.go create mode 100644 internal/app/wwctl/genconf/man/root.go diff --git a/Makefile b/Makefile index c2365b1e..59927775 100644 --- a/Makefile +++ b/Makefile @@ -196,6 +196,7 @@ files: all chmod 644 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/warewulf/config.ww chmod 750 $(DESTDIR)$(WWOVERLAYDIR)/host install -m 0755 wwctl $(DESTDIR)$(BINDIR) + install -m 0755 wwclient $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/wwclient install -m 0755 wwapic $(DESTDIR)$(BINDIR) install -m 0755 wwapid $(DESTDIR)$(BINDIR) install -m 0755 wwapird $(DESTDIR)$(BINDIR) @@ -224,17 +225,9 @@ wwclient: $(WWCLIENT_DEPS) @ cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags "-extldflags -static \ -X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=/etc/warewulf/warewulf.conf'" -o ../../wwclient -install_wwclient: wwclient - install -m 0755 wwclient $(DESTDIR)$(WWOVERLAYDIR)/wwinit/$(WWCLIENTDIR)/wwclient - -man_page: - cd cmd/man_page && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\ - -X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\ - -mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../man_page - -man_pages: man_page +man_pages: wwctl install -d man_pages - ./man_page ./man_pages + ./wwctl genconfig man man_pages cp docs/man/man5/*.5 ./man_pages/ cd man_pages; for i in wwctl*1 *.5; do echo "Compressing manpage: $$i"; gzip --force $$i; done @@ -272,7 +265,7 @@ dist: vendor config ## sudo make install ## sudo ldconfig # refresh shared library cache. ## To setup protoc-gen-grpc-gateway, see https://github.com/grpc-ecosystem/grpc-gateway -proto: +proto: rm -rf internal/pkg/api/routes/wwapiv1/ protoc -I internal/pkg/api/routes/v1 -I=. \ --grpc-gateway_out=. \ @@ -295,7 +288,6 @@ contclean: rm -f wwctl rm -rf .dist rm -f $(WAREWULF)-$(VERSION).tar.gz - rm -f man_page rm -rf man_pages rm -f warewulf.spec rm -f config @@ -309,6 +301,6 @@ contclean: clean: contclean rm -rf vendor -install: files install_wwclient +install: files debinstall: files debfiles diff --git a/cmd/bash_completion/bash_completion.go b/cmd/bash_completion/bash_completion.go deleted file mode 100644 index 752884bc..00000000 --- a/cmd/bash_completion/bash_completion.go +++ /dev/null @@ -1,23 +0,0 @@ -// usage: ./bash_completion -package main - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/app/wwctl" - "os" -) - -func main() { - fh, err := os.Create(os.Args[1]) - if err != nil { - fmt.Println(err) - return - } - - defer fh.Close() - - if err := wwctl.GenBashCompletion(fh); err != nil { - fmt.Println(err) - return - } -} diff --git a/cmd/man_page/man_page.go b/cmd/man_page/man_page.go deleted file mode 100644 index 8a35a3be..00000000 --- a/cmd/man_page/man_page.go +++ /dev/null @@ -1,17 +0,0 @@ -// Generate man pages for wwctl command. -// usage: ./man_page -package main - -import ( - "fmt" - "github.com/hpcng/warewulf/internal/app/wwctl" - "os" -) - -func main() { - - if err := wwctl.GenManTree(os.Args[1]); err != nil { - fmt.Println(err) - return - } -} diff --git a/internal/app/wwctl/genconf/completions/main.go b/internal/app/wwctl/genconf/completions/main.go index 53827131..01557f52 100644 --- a/internal/app/wwctl/genconf/completions/main.go +++ b/internal/app/wwctl/genconf/completions/main.go @@ -6,18 +6,18 @@ import ( "github.com/spf13/cobra" ) -func CobraRunE(cmd *cobra.Command, args []string) error { +func CobraRunE(cmd *cobra.Command, args []string) (err error) { myArg := "bash" if len(args) == 1 { myArg = args[0] } switch myArg { case "zsh": - cmd.GenZshCompletion(os.Stdout) + err = cmd.Parent().Parent().GenZshCompletion(os.Stdout) case "fish": - cmd.GenFishCompletion(os.Stdout, true) + err = cmd.Parent().Parent().GenFishCompletion(os.Stdout, true) default: - cmd.GenBashCompletion(os.Stdout) + err = cmd.Parent().Parent().GenBashCompletion(os.Stdout) } - return nil + return } diff --git a/internal/app/wwctl/genconf/man/main.go b/internal/app/wwctl/genconf/man/main.go new file mode 100644 index 00000000..3e752307 --- /dev/null +++ b/internal/app/wwctl/genconf/man/main.go @@ -0,0 +1,15 @@ +package man + +import ( + "github.com/spf13/cobra" + "github.com/spf13/cobra/doc" +) + +func CobraRunE(cmd *cobra.Command, args []string) (err error) { + header := &doc.GenManHeader{ + Title: "WWCTL", + Section: "1", + } + err = doc.GenManTree(cmd.Parent().Parent(), header, args[0]) + return +} diff --git a/internal/app/wwctl/genconf/man/root.go b/internal/app/wwctl/genconf/man/root.go new file mode 100644 index 00000000..d450e5d3 --- /dev/null +++ b/internal/app/wwctl/genconf/man/root.go @@ -0,0 +1,23 @@ +package man + +import ( + "github.com/spf13/cobra" +) + +var ( + baseCmd = &cobra.Command{ + Use: "man", + Short: "manpage generation", + Long: "This command generates the man pages for all commands, needs target dir as argument", + RunE: CobraRunE, + Args: cobra.ExactArgs(1), + Aliases: []string{"man_pages"}, + } +) + +func init() { +} + +func GetCommand() *cobra.Command { + return baseCmd +} diff --git a/internal/app/wwctl/genconf/root.go b/internal/app/wwctl/genconf/root.go index 3584164d..0c8afb2f 100644 --- a/internal/app/wwctl/genconf/root.go +++ b/internal/app/wwctl/genconf/root.go @@ -2,6 +2,7 @@ package genconf import ( "github.com/hpcng/warewulf/internal/app/wwctl/genconf/completions" + "github.com/hpcng/warewulf/internal/app/wwctl/genconf/man" "github.com/spf13/cobra" ) @@ -13,11 +14,13 @@ var ( Args: cobra.ExactArgs(0), Aliases: []string{"cnf"}, } - ListFull bool + ListFull bool + WWctlRoot *cobra.Command ) func init() { baseCmd.AddCommand(completions.GetCommand()) + baseCmd.AddCommand(man.GetCommand()) } // GetRootCommand returns the root cobra.Command for the application. diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index f60918b1..20a02657 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -15,9 +15,6 @@ import ( "github.com/hpcng/warewulf/internal/pkg/help" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" - "github.com/spf13/cobra/doc" - - "io" ) var ( @@ -74,19 +71,3 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) error { } return nil } - -// External functions not used by the wwctl command line - -// Generate Bash completion file -func GenBashCompletion(w io.Writer) error { - return rootCmd.GenBashCompletion(w) -} - -// Generate man pages -func GenManTree(fileName string) error { - header := &doc.GenManHeader{ - Title: "WWCTL", - Section: "1", - } - return doc.GenManTree(rootCmd, header, fileName) -}