1package commands
2
3import (
4 "flag"
5 "fmt"
6 "github.com/MichaelMure/git-bug/repository"
7 "sort"
8)
9
10var commandsFlagSet = flag.NewFlagSet("commands", flag.ExitOnError)
11
12var (
13 commandsDesc = commandsFlagSet.Bool("pretty", false, "Output the command description as well as Markdown compatible comment")
14)
15
16func runCommands(repo repository.Repo, args []string) error {
17 commandsFlagSet.Parse(args)
18 args = commandsFlagSet.Args()
19
20 first := true
21
22 keys := make([]string, 0, len(CommandMap))
23
24 for key := range CommandMap {
25 keys = append(keys, key)
26 }
27
28 sort.Strings(keys)
29
30 for _, key := range keys {
31 if !first {
32 fmt.Println()
33 }
34
35 first = false
36
37 cmd := CommandMap[key]
38
39 if *commandsDesc {
40 fmt.Printf("# %s\n", cmd.Description)
41 }
42
43 // TODO: the root name command ("git bug") should be passed from git-bug.go but well ...
44 fmt.Printf("%s %s %s\n", "git bug", key, cmd.Usage)
45 }
46
47 return nil
48}
49
50var commandsCmd = &Command{
51 Description: "Display available commands",
52 Usage: "[<option>...]",
53 flagSet: commandsFlagSet,
54 RunMethod: runCommands,
55}