diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-16 01:17:06 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-16 01:17:06 +0200 |
commit | ae100e0e8273b09dd1c2f2ee08388440c2662fad (patch) | |
tree | b2663d0e0984d6c8fdd47c37ed71eb873156cab5 /commands/title_edit.go | |
parent | d9f7269507cfc65a2fec05651bdff00978e0d1ec (diff) | |
download | git-bug-ae100e0e8273b09dd1c2f2ee08388440c2662fad.tar.gz |
commands: add a title edit command
Diffstat (limited to 'commands/title_edit.go')
-rw-r--r-- | commands/title_edit.go | 75 |
1 files changed, 75 insertions, 0 deletions
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", + ) +} |