aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands.go
blob: 0a3c33ad968bc60d08bb0922a54c1deae5310372 (plain) (blame)
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
package commands

import (
	"flag"
	"fmt"
	"github.com/MichaelMure/git-bug/repository"
)

var commandsFlagSet = flag.NewFlagSet("commands", flag.ExitOnError)

var (
	commandsDesc = commandsFlagSet.Bool("pretty", false, "Output the command description as well as Markdown compatible comment")
)

func runCommands(repo repository.Repo, args []string) error {
	commandsFlagSet.Parse(args)
	args = commandsFlagSet.Args()

	first := true

	for name, cmd := range CommandMap {
		if !first {
			fmt.Println()
		}

		first = false

		if *commandsDesc {
			fmt.Printf("# %s\n", cmd.Description)
		}

		// TODO: the root name command ("git bug") should be passed from git-bug.go but well ...
		fmt.Printf("%s %s %s\n", "git bug", name, cmd.Usage)
	}

	return nil
}

var commandsCmd = &Command{
	Description: "Display available commands",
	Usage:       "[<option>...]",
	flagSet:     commandsFlagSet,
	RunMethod:   runCommands,
}