diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/close.go | 17 | ||||
-rw-r--r-- | commands/comment.go | 19 | ||||
-rw-r--r-- | commands/label.go | 21 | ||||
-rw-r--r-- | commands/ls.go | 7 | ||||
-rw-r--r-- | commands/new.go | 26 | ||||
-rw-r--r-- | commands/open.go | 17 | ||||
-rw-r--r-- | commands/pull.go | 10 | ||||
-rw-r--r-- | commands/push.go | 10 | ||||
-rw-r--r-- | commands/root.go | 13 | ||||
-rw-r--r-- | commands/show.go | 12 | ||||
-rw-r--r-- | commands/termui.go | 9 |
11 files changed, 91 insertions, 70 deletions
diff --git a/commands/close.go b/commands/close.go index 10420a4e..890702dd 100644 --- a/commands/close.go +++ b/commands/close.go @@ -3,8 +3,7 @@ package commands import ( "errors" - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/cache" "github.com/spf13/cobra" ) @@ -17,21 +16,25 @@ func runCloseBug(cmd *cobra.Command, args []string) error { return errors.New("You must provide a bug id") } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + prefix := args[0] - b, err := bug.FindLocalBug(repo, prefix) + b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - author, err := bug.GetUser(repo) + err = b.Close() if err != nil { return err } - operations.Close(b, author) - - return b.Commit(repo) + return b.Commit() } var closeCmd = &cobra.Command{ diff --git a/commands/comment.go b/commands/comment.go index 97aa18aa..0f45c18d 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -4,8 +4,7 @@ import ( "errors" "fmt" - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/input" "github.com/spf13/cobra" ) @@ -26,6 +25,12 @@ func runComment(cmd *cobra.Command, args []string) error { return errors.New("You must provide a bug id") } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + prefix := args[0] if commentMessageFile != "" && commentMessage == "" { @@ -36,7 +41,7 @@ func runComment(cmd *cobra.Command, args []string) error { } if commentMessage == "" { - commentMessage, err = input.BugCommentEditorInput(repo) + commentMessage, err = input.BugCommentEditorInput(backend.Repository()) if err == input.ErrEmptyMessage { fmt.Println("Empty message, aborting.") return nil @@ -46,19 +51,17 @@ func runComment(cmd *cobra.Command, args []string) error { } } - author, err := bug.GetUser(repo) + b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - b, err := bug.FindLocalBug(repo, prefix) + err = b.AddComment(commentMessage) if err != nil { return err } - operations.Comment(b, author, commentMessage) - - return b.Commit(repo) + return b.Commit() } var commentCmd = &cobra.Command{ diff --git a/commands/label.go b/commands/label.go index 6c729ff5..b545852f 100644 --- a/commands/label.go +++ b/commands/label.go @@ -4,8 +4,7 @@ import ( "errors" "os" - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/cache" "github.com/spf13/cobra" ) @@ -20,6 +19,12 @@ func runLabel(cmd *cobra.Command, args []string) error { return errors.New("You must provide a label") } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + prefix := args[0] var add, remove []string @@ -30,23 +35,17 @@ func runLabel(cmd *cobra.Command, args []string) error { add = args[1:] } - b, err := bug.FindLocalBug(repo, prefix) + b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - author, err := bug.GetUser(repo) - if err != nil { - return err - } - - err = operations.ChangeLabels(os.Stdout, b, author, add, remove) - + err = b.ChangeLabels(os.Stdout, add, remove) if err != nil { return err } - return b.Commit(repo) + return b.Commit() } var labelCmd = &cobra.Command{ diff --git a/commands/ls.go b/commands/ls.go index 30aa7bdc..533f3d1e 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -9,6 +9,13 @@ import ( ) func runLsBug(cmd *cobra.Command, args []string) error { + //backend, err := cache.NewRepoCache(repo) + //if err != nil { + // return err + //} + + // Todo: read bugs from backend + bugs := bug.ReadAllLocalBugs(repo) for b := range bugs { diff --git a/commands/new.go b/commands/new.go index bd0966e5..ce6479f1 100644 --- a/commands/new.go +++ b/commands/new.go @@ -3,8 +3,7 @@ package commands import ( "fmt" - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/input" "github.com/spf13/cobra" ) @@ -25,8 +24,14 @@ func runNewBug(cmd *cobra.Command, args []string) error { } } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + if newMessage == "" || newTitle == "" { - newTitle, newMessage, err = input.BugCreateEditorInput(repo, newTitle, newMessage) + newTitle, newMessage, err = input.BugCreateEditorInput(backend.Repository(), newTitle, newMessage) if err == input.ErrEmptyTitle { fmt.Println("Empty title, aborting.") @@ -37,23 +42,12 @@ func runNewBug(cmd *cobra.Command, args []string) error { } } - author, err := bug.GetUser(repo) - if err != nil { - return err - } - - newBug, err := operations.Create(author, newTitle, newMessage) - if err != nil { - return err - } - - err = newBug.Commit(repo) - + b, err := backend.NewBug(newTitle, newMessage) if err != nil { return err } - fmt.Printf("%s created\n", newBug.HumanId()) + fmt.Printf("%s created\n", b.HumanId()) return nil } diff --git a/commands/open.go b/commands/open.go index 8a5ede3d..db6a5909 100644 --- a/commands/open.go +++ b/commands/open.go @@ -3,8 +3,7 @@ package commands import ( "errors" - "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/bug/operations" + "github.com/MichaelMure/git-bug/cache" "github.com/spf13/cobra" ) @@ -17,21 +16,25 @@ func runOpenBug(cmd *cobra.Command, args []string) error { return errors.New("You must provide a bug id") } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + prefix := args[0] - b, err := bug.FindLocalBug(repo, prefix) + b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - author, err := bug.GetUser(repo) + err = b.Open() if err != nil { return err } - operations.Open(b, author) - - return b.Commit(repo) + return b.Commit() } var openCmd = &cobra.Command{ diff --git a/commands/pull.go b/commands/pull.go index ff07912a..e9f0ad3e 100644 --- a/commands/pull.go +++ b/commands/pull.go @@ -4,7 +4,7 @@ import ( "errors" "os" - "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/cache" "github.com/spf13/cobra" ) @@ -18,7 +18,13 @@ func runPull(cmd *cobra.Command, args []string) error { remote = args[0] } - return bug.Pull(repo, os.Stdout, remote) + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + return backend.Pull(remote, os.Stdout) } // showCmd defines the "push" subcommand. diff --git a/commands/push.go b/commands/push.go index 86c37b46..06a4044b 100644 --- a/commands/push.go +++ b/commands/push.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/cache" "github.com/spf13/cobra" ) @@ -18,7 +18,13 @@ func runPush(cmd *cobra.Command, args []string) error { remote = args[0] } - stdout, err := bug.Push(repo, remote) + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + stdout, err := backend.Push(remote) if err != nil { return err } diff --git a/commands/root.go b/commands/root.go index 9435ce64..62351055 100644 --- a/commands/root.go +++ b/commands/root.go @@ -5,15 +5,10 @@ import ( "os" "github.com/MichaelMure/git-bug/bug" - "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/repository" "github.com/spf13/cobra" ) -// Will display "git bug" -// \u00A0 is a non-breaking space -// It's used to avoid cobra to split the Use string at the first space to get the root command name -//const rootCommandName = "git\u00A0bug" const rootCommandName = "git-bug" // package scoped var to hold the repo after the PreRun execution @@ -69,13 +64,5 @@ func loadRepo(cmd *cobra.Command, args []string) error { return err } - // Prevent the command from running when the cache has locked the repo - // Todo: make it more fine-grained at first - // Todo: make the running cache available for other processes - err = cache.RepoIsAvailable(repo) - if err != nil { - return err - } - return nil } diff --git a/commands/show.go b/commands/show.go index fe7581a7..71ec1b57 100644 --- a/commands/show.go +++ b/commands/show.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util" "github.com/spf13/cobra" ) @@ -19,14 +19,20 @@ func runShowBug(cmd *cobra.Command, args []string) error { return errors.New("You must provide a bug id") } + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + prefix := args[0] - b, err := bug.FindLocalBug(repo, prefix) + b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - snapshot := b.Compile() + snapshot := b.Snapshot() if len(snapshot.Comments) == 0 { return errors.New("Invalid bug: no comment") diff --git a/commands/termui.go b/commands/termui.go index 460770a6..5d600710 100644 --- a/commands/termui.go +++ b/commands/termui.go @@ -1,12 +1,19 @@ package commands import ( + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/termui" "github.com/spf13/cobra" ) func runTermUI(cmd *cobra.Command, args []string) error { - return termui.Run(repo) + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + return termui.Run(backend) } var termUICmd = &cobra.Command{ |