1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package main
import (
"fmt"
"os"
mcobra "github.com/muesli/mango-cobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "mango",
Short: "A man-page generator",
Long: "mango is a man-page generator for the Go flag, pflag, and cobra packages.\n" +
"Features:\n" +
"* User-friendly\n" +
"* Plugable",
RunE: func(cmd *cobra.Command, agrs []string) error {
return nil
},
}
oneCmd = &cobra.Command{
Use: "1 [arg]",
Example: "1 foobar",
Short: "The first command",
RunE: func(cmd *cobra.Command, agrs []string) error {
return nil
},
}
twoCmd = &cobra.Command{
Use: "2",
Short: "The second command",
RunE: func(cmd *cobra.Command, agrs []string) error {
return nil
},
}
config string
one string
two string
)
func init() {
rootCmd.PersistentFlags().StringVar(&config, "config", "", "config file (default is $HOME/.mango.yaml)")
oneCmd.Flags().StringVar(&one, "one", "", "first value")
oneCmd.Flags().StringVar(&two, "two", "", "second value")
rootCmd.AddCommand(oneCmd)
rootCmd.AddCommand(twoCmd)
}
func main() {
manPage, err := mcobra.NewManPage(1, rootCmd)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
manPage = manPage.WithSection("Authors", "mango was written by Christian Muehlhaeuser <https://github.com/muesli/mango>").
WithSection("Copyright", "Copyright (C) 2022 Christian Muehlhaeuser.\n"+
"Released under MIT license.")
fmt.Println(manPage.Build(roff.NewDocument()))
}
|