commands.go

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