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 ab2139a1fd
commit 94866656a4
8 changed files with 52 additions and 78 deletions

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.