-
Notifications
You must be signed in to change notification settings - Fork 937
/
Copy pathmanpage.go
75 lines (58 loc) · 1.65 KB
/
manpage.go
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
69
70
71
72
73
74
75
package main
import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/canonical/lxd/shared"
cli "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/lxd/shared/i18n"
)
type cmdManpage struct {
global *cmdGlobal
flagFormat string
}
func (c *cmdManpage) command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = usage("manpage", i18n.G("<target>"))
cmd.Short = i18n.G("Generate manpages for all commands")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Generate manpages for all commands`))
cmd.Hidden = true
cmd.Flags().StringVarP(&c.flagFormat, "format", "f", "man", i18n.G("Format (man|md|rest|yaml)")+"``")
cmd.RunE = c.run
return cmd
}
func (c *cmdManpage) run(cmd *cobra.Command, args []string) error {
// Quick checks.
exit, err := c.global.CheckArgs(cmd, args, 1, 1)
if exit {
return err
}
// If asked to do all commands, mark them all visible.
for _, c := range c.global.cmd.Commands() {
if c.Name() == "completion" {
continue
}
c.Hidden = false
}
// Generate the documentation.
switch c.flagFormat {
case "man":
header := &doc.GenManHeader{
Title: i18n.G("LXD - Command line client"),
Section: "1",
}
opts := doc.GenManTreeOptions{
Header: header,
Path: shared.HostPathFollow(args[0]),
CommandSeparator: ".",
}
err = doc.GenManTreeFromOpts(c.global.cmd, opts)
case "md":
err = doc.GenMarkdownTree(c.global.cmd, shared.HostPathFollow(args[0]))
case "rest":
err = doc.GenReSTTree(c.global.cmd, shared.HostPathFollow(args[0]))
case "yaml":
err = doc.GenYamlTree(c.global.cmd, shared.HostPathFollow(args[0]))
}
return err
}