commands: add a title edit command

Michael Muré created

Change summary

commands/title.go            |  2 
commands/title_edit.go       | 75 ++++++++++++++++++++++++++++++++++++++
doc/man/git-bug-title-edit.1 | 33 ++++++++++++++++
doc/man/git-bug-title.1      |  6 +-
doc/md/git-bug.md            |  2 
doc/md/git-bug_title.md      |  5 +-
doc/md/git-bug_title_edit.md | 23 +++++++++++
misc/bash_completion/git-bug | 24 ++++++++++++
misc/zsh_completion/git-bug  |  3 +
9 files changed, 166 insertions(+), 7 deletions(-)

Detailed changes

commands/title.go 🔗

@@ -48,5 +48,5 @@ var titleCmd = &cobra.Command{
 func init() {
 	RootCmd.AddCommand(titleCmd)
 
-	commentCmd.Flags().SortFlags = false
+	titleCmd.Flags().SortFlags = false
 }

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",
+	)
+}

doc/man/git-bug-title-edit.1 🔗

@@ -0,0 +1,33 @@
+.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" "" 
+.nh
+.ad l
+
+
+.SH NAME
+.PP
+git\-bug\-title\-edit \- Edit a bug title
+
+
+.SH SYNOPSIS
+.PP
+\fBgit\-bug title edit <id> [flags]\fP
+
+
+.SH DESCRIPTION
+.PP
+Edit a bug title
+
+
+.SH OPTIONS
+.PP
+\fB\-t\fP, \fB\-\-title\fP=""
+    Provide a title to describe the issue
+
+.PP
+\fB\-h\fP, \fB\-\-help\fP[=false]
+    help for edit
+
+
+.SH SEE ALSO
+.PP
+\fBgit\-bug\-title(1)\fP

doc/man/git-bug-title.1 🔗

@@ -5,7 +5,7 @@
 
 .SH NAME
 .PP
-git\-bug\-title \- Show a bug's title
+git\-bug\-title \- Display a bug's title
 
 
 .SH SYNOPSIS
@@ -15,7 +15,7 @@ git\-bug\-title \- Show a bug's title
 
 .SH DESCRIPTION
 .PP
-Show a bug's title
+Display a bug's title
 
 
 .SH OPTIONS
@@ -26,4 +26,4 @@ Show a bug's title
 
 .SH SEE ALSO
 .PP
-\fBgit\-bug(1)\fP
+\fBgit\-bug(1)\fP, \fBgit\-bug\-title\-edit(1)\fP

doc/md/git-bug.md 🔗

@@ -31,6 +31,6 @@ git-bug [flags]
 * [git-bug push](git-bug_push.md)	 - Push bugs update to a git remote
 * [git-bug show](git-bug_show.md)	 - Display the details of a bug
 * [git-bug termui](git-bug_termui.md)	 - Launch the terminal UI
-* [git-bug title](git-bug_title.md)	 - Show a bug's title
+* [git-bug title](git-bug_title.md)	 - Display a bug's title
 * [git-bug webui](git-bug_webui.md)	 - Launch the web UI
 

doc/md/git-bug_title.md 🔗

@@ -1,10 +1,10 @@
 ## git-bug title
 
-Show a bug's title
+Display a bug's title
 
 ### Synopsis
 
-Show a bug's title
+Display a bug's title
 
 ```
 git-bug title <id> [flags]
@@ -19,4 +19,5 @@ git-bug title <id> [flags]
 ### SEE ALSO
 
 * [git-bug](git-bug.md)	 - A bugtracker embedded in Git
+* [git-bug title edit](git-bug_title_edit.md)	 - Edit a bug title
 

doc/md/git-bug_title_edit.md 🔗

@@ -0,0 +1,23 @@
+## git-bug title edit
+
+Edit a bug title
+
+### Synopsis
+
+Edit a bug title
+
+```
+git-bug title edit <id> [flags]
+```
+
+### Options
+
+```
+  -t, --title string   Provide a title to describe the issue
+  -h, --help           help for edit
+```
+
+### SEE ALSO
+
+* [git-bug title](git-bug_title.md)	 - Display a bug's title
+

misc/bash_completion/git-bug 🔗

@@ -528,6 +528,29 @@ _git-bug_termui()
     noun_aliases=()
 }
 
+_git-bug_title_edit()
+{
+    last_command="git-bug_title_edit"
+
+    command_aliases=()
+
+    commands=()
+
+    flags=()
+    two_word_flags=()
+    local_nonpersistent_flags=()
+    flags_with_completion=()
+    flags_completion=()
+
+    flags+=("--title=")
+    two_word_flags+=("-t")
+    local_nonpersistent_flags+=("--title=")
+
+    must_have_one_flag=()
+    must_have_one_noun=()
+    noun_aliases=()
+}
+
 _git-bug_title()
 {
     last_command="git-bug_title"
@@ -535,6 +558,7 @@ _git-bug_title()
     command_aliases=()
 
     commands=()
+    commands+=("edit")
 
     flags=()
     two_word_flags=()

misc/zsh_completion/git-bug 🔗

@@ -20,6 +20,9 @@ case $state in
       comment)
         _arguments '2: :(add)'
       ;;
+      title)
+        _arguments '2: :(edit)'
+      ;;
       *)
         _arguments '*: :_files'
       ;;