aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-16 15:21:21 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-16 15:21:21 +0200
commitd3893a5e04868fb99df28c8da62a0ee59d7e9064 (patch)
tree0f702ca72b82cd2429c4451f77baf99156525852 /commands/commands.go
parent9423e7fdb6f70afb37f567d86a97594b06d43eb1 (diff)
downloadgit-bug-d3893a5e04868fb99df28c8da62a0ee59d7e9064.tar.gz
rework the commands thing and add a "commands" command to list all commands
Diffstat (limited to 'commands/commands.go')
-rw-r--r--commands/commands.go53
1 files changed, 33 insertions, 20 deletions
diff --git a/commands/commands.go b/commands/commands.go
index faca02ab..0a3c33ad 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -1,31 +1,44 @@
-// Package commands contains the assorted sub commands supported by the git-bug tool.
package commands
import (
+ "flag"
+ "fmt"
"github.com/MichaelMure/git-bug/repository"
)
-const messageFilename = "BUG_MESSAGE_EDITMSG"
+var commandsFlagSet = flag.NewFlagSet("commands", flag.ExitOnError)
-// Command represents the definition of a single command.
-type Command struct {
- Usage func(string)
- RunMethod func(repository.Repo, []string) error
-}
+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)
+ }
-// Run executes a command, given its arguments.
-//
-// The args parameter is all of the command line args that followed the
-// subcommand.
-func (cmd *Command) Run(repo repository.Repo, args []string) error {
- return cmd.RunMethod(repo, args)
+ return nil
}
-// CommandMap defines all of the available (sub)commands.
-var CommandMap = map[string]*Command{
- "comment": commentCmd,
- "ls": lsCmd,
- "new": newCmd,
- "pull": pullCmd,
- "push": pushCmd,
+var commandsCmd = &Command{
+ Description: "Display available commands",
+ Usage: "[<option>...]",
+ flagSet: commandsFlagSet,
+ RunMethod: runCommands,
}