package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
func newManCmd() *cobra.Command {
var outDir string
cmd := &cobra.Command{
Use: "man",
Short: "Generate man pages for httptap into a directory",
Hidden: true,
RunE: func(c *cobra.Command, args []string) error {
if outDir == "" {
return fmt.Errorf("man: --out is required")
}
if err := os.MkdirAll(outDir, 0o755); err != nil {
return err
}
header := &doc.GenManHeader{
Title: "HTTPTAP",
Section: "1",
Source: "httptap",
Manual: "User Commands",
}
return doc.GenManTree(c.Root(), header, outDir)
},
}
cmd.Flags().StringVar(&outDir, "out", "", "directory to write .1 pages")
return cmd
}
// ManPagePath is the conventional install path for the top-level page.
func ManPagePath() string {
prefix := os.Getenv("PREFIX")
if prefix == "" {
prefix = "/usr/local"
}
return filepath.Join(prefix, "share", "man", "man1", "httptap.1")
}
// InstallBanner is the short message printed after `httptap man
// --install` so users know where the files landed. Currently unused.
func InstallBanner(dir string) string {
return fmt.Sprintf("wrote man pages to %s", dir)
}