This repository has been archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dump_readme.go
72 lines (52 loc) · 1.24 KB
/
dump_readme.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
// Copyright © 2016-present Thomas Rabaix <[email protected]>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package commands
import (
"flag"
"fmt"
"sort"
"strings"
"github.com/mitchellh/cli"
)
type DumpReadmeCommand struct {
Ui cli.Ui
Verbose bool
Commands map[string]cli.CommandFactory
}
func (c *DumpReadmeCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("dump:readme", flag.ContinueOnError)
cmdFlags.Usage = func() {
c.Ui.Output(c.Help())
}
cmdFlags.BoolVar(&c.Verbose, "verbose", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
mk := make([]string, len(c.Commands))
i := 0
for k := range c.Commands {
mk[i] = k
i++
}
sort.Strings(mk)
c.Ui.Output("## Commands")
for _, name := range mk {
if name == "dump:readme" {
continue
}
cmd, _ := c.Commands[name]()
c.Ui.Output(fmt.Sprintf("\n### %s\n", name))
for _, l := range strings.Split(cmd.Help(), "\n") {
c.Ui.Output(fmt.Sprintf(" %s", l))
}
}
return 0
}
func (c *DumpReadmeCommand) Synopsis() string {
return "Dump the command readme."
}
func (c *DumpReadmeCommand) Help() string {
return strings.TrimSpace("Dump the command readme.")
}