aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/title.go2
-rw-r--r--commands/title_edit.go75
2 files changed, 76 insertions, 1 deletions
diff --git a/commands/title.go b/commands/title.go
index 70355986..16cfc342 100644
--- a/commands/title.go
+++ b/commands/title.go
@@ -48,5 +48,5 @@ var titleCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(titleCmd)
- commentCmd.Flags().SortFlags = false
+ titleCmd.Flags().SortFlags = false
}
diff --git a/commands/title_edit.go b/commands/title_edit.go
new file mode 100644
index 00000000..111c6325
--- /dev/null
+++ b/commands/title_edit.go
@@ -0,0 +1,75 @@
+package commands
+
+import (
+ "errors"
+ "fmt"
+
+ "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/input"
+ "github.com/spf13/cobra"
+)
+
+var (
+ titleEditTitle string
+)
+
+func runTitleEdit(cmd *cobra.Command, args []string) error {
+ var err error
+
+ if len(args) > 1 {
+ return errors.New("Only one bug id is supported")
+ }
+
+ if len(args) == 0 {
+ 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 := backend.ResolveBugPrefix(prefix)
+ if err != nil {
+ return err
+ }
+
+ snap := b.Snapshot()
+
+ if titleEditTitle == "" {
+ titleEditTitle, err = input.BugTitleEditorInput(repo, snap.Title)
+ if err == input.ErrEmptyTitle {
+ fmt.Println("Empty title, aborting.")
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ }
+
+ err = b.SetTitle(titleEditTitle)
+ if err != nil {
+ return err
+ }
+
+ return b.Commit()
+}
+
+var titleEditCmd = &cobra.Command{
+ Use: "edit <id>",
+ Short: "Edit a bug title",
+ RunE: runTitleEdit,
+}
+
+func init() {
+ titleCmd.AddCommand(titleEditCmd)
+
+ titleEditCmd.Flags().SortFlags = false
+
+ titleEditCmd.Flags().StringVarP(&titleEditTitle, "title", "t", "",
+ "Provide a title to describe the issue",
+ )
+}