aboutsummaryrefslogtreecommitdiffstats
path: root/git-bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-19 12:30:25 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-19 12:36:01 +0200
commit7f5922f905831a85ffee4c9226b65715899ba758 (patch)
treed18a29a2ec13706efa7f5e9efc9515a92cf4513d /git-bug.go
parent459bb8747d9e84493b8d04a3172e6758452a75b9 (diff)
downloadgit-bug-7f5922f905831a85ffee4c9226b65715899ba758.tar.gz
rework all the commands to use cobra as a parser
Diffstat (limited to 'git-bug.go')
-rw-r--r--git-bug.go80
1 files changed, 2 insertions, 78 deletions
diff --git a/git-bug.go b/git-bug.go
index 21cb8d4a..3aeb8ff6 100644
--- a/git-bug.go
+++ b/git-bug.go
@@ -2,84 +2,8 @@
package main
-import (
- "fmt"
- "github.com/MichaelMure/git-bug/commands"
- "github.com/MichaelMure/git-bug/repository"
- "os"
- "sort"
- "strings"
-)
-
-const rootCommandName = "git bug"
-const usageMessageTemplate = `Usage: %s <command>
-
-Where <command> is one of:
- %s
-
-For individual command usage, run:
- %s help <command>
-`
-
-func rootUsage() {
- var subcommands []string
- for subcommand := range commands.CommandMap {
- subcommands = append(subcommands, subcommand)
- }
- sort.Strings(subcommands)
- fmt.Printf(usageMessageTemplate, rootCommandName, strings.Join(subcommands, "\n "), rootCommandName)
-}
-
-func help(command string) {
- subcommand, ok := commands.CommandMap[command]
- if !ok {
- fmt.Printf("Unknown command %q\n", command)
- rootUsage()
- return
- }
- subcommand.PrintUsage(rootCommandName, command)
-}
+import "github.com/MichaelMure/git-bug/commands"
func main() {
- args := os.Args
-
- // git bug
- if len(args) == 1 {
- fmt.Println("Will list bugs, not implemented yet")
- //TODO: list bugs
- return
- }
-
- if args[1] == "help" {
- if len(args) == 2 {
- // git bug help
- rootUsage()
- } else {
- // git bug help <command>
- help(args[2])
- }
- return
- }
-
- cwd, err := os.Getwd()
- if err != nil {
- fmt.Printf("Unable to get the current working directory: %q\n", err)
- return
- }
- repo, err := repository.NewGitRepo(cwd)
- if err != nil {
- fmt.Printf("%s must be run from within a git repo.\n", rootCommandName)
- return
- }
-
- subcommand, ok := commands.CommandMap[args[1]]
- if !ok {
- fmt.Printf("Unknown command: %q\n", args[1])
- rootUsage()
- return
- }
- if err := subcommand.Run(repo, args[2:]); err != nil {
- fmt.Println(err.Error())
- os.Exit(1)
- }
+ commands.Execute()
}