commands: add a title edit command

This commit is contained in:
Michael Muré 2018-09-16 01:17:06 +02:00
parent d9f7269507
commit ae100e0e82
No known key found for this signature in database
GPG Key ID: A4457C029293126F
9 changed files with 166 additions and 7 deletions

View File

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

75
commands/title_edit.go Normal file
View File

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

View File

@ -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

View File

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

View File

@ -31,6 +31,6 @@ git-bug [flags]
* [git-bug push](git-bug_push.md) - Push bugs update to a git remote * [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 show](git-bug_show.md) - Display the details of a bug
* [git-bug termui](git-bug_termui.md) - Launch the terminal UI * [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 * [git-bug webui](git-bug_webui.md) - Launch the web UI

View File

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

View File

@ -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

View File

@ -528,6 +528,29 @@ _git-bug_termui()
noun_aliases=() 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() _git-bug_title()
{ {
last_command="git-bug_title" last_command="git-bug_title"
@ -535,6 +558,7 @@ _git-bug_title()
command_aliases=() command_aliases=()
commands=() commands=()
commands+=("edit")
flags=() flags=()
two_word_flags=() two_word_flags=()

View File

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