From ae100e0e8273b09dd1c2f2ee08388440c2662fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 16 Sep 2018 01:17:06 +0200 Subject: [PATCH] commands: add a title edit command --- 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(-) create mode 100644 commands/title_edit.go create mode 100644 doc/man/git-bug-title-edit.1 create mode 100644 doc/md/git-bug_title_edit.md 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 ", + 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", + ) +} diff --git a/doc/man/git-bug-title-edit.1 b/doc/man/git-bug-title-edit.1 new file mode 100644 index 00000000..62895f7e --- /dev/null +++ b/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 [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 diff --git a/doc/man/git-bug-title.1 b/doc/man/git-bug-title.1 index 3d6adc43..a4493571 100644 --- a/doc/man/git-bug-title.1 +++ b/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 diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md index c99afe7e..9eb7b7bc 100644 --- a/doc/md/git-bug.md +++ b/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 diff --git a/doc/md/git-bug_title.md b/doc/md/git-bug_title.md index c3a633dd..22b40d65 100644 --- a/doc/md/git-bug_title.md +++ b/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 [flags] @@ -19,4 +19,5 @@ git-bug title [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 diff --git a/doc/md/git-bug_title_edit.md b/doc/md/git-bug_title_edit.md new file mode 100644 index 00000000..ee7fda02 --- /dev/null +++ b/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 [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 + diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 36da665c..f5f3da2a 100644 --- a/misc/bash_completion/git-bug +++ b/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=() diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 31dd5ee0..60ae6ce9 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -20,6 +20,9 @@ case $state in comment) _arguments '2: :(add)' ;; + title) + _arguments '2: :(edit)' + ;; *) _arguments '*: :_files' ;;