generate man pages via sub command

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2023-03-02 11:01:11 +01:00
parent 3526c2bd5f
commit ee7bc75bd7
8 changed files with 52 additions and 78 deletions

View File

@@ -196,6 +196,7 @@ files: all
chmod 600 $(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

View File

@@ -1,23 +0,0 @@
// usage: ./bash_completion <FILE>
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
}
}

View File

@@ -1,17 +0,0 @@
// Generate man pages for wwctl command.
// usage: ./man_page <DIRECTORY>
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
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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.

View File

@@ -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)
}