1package commands
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/commands/select"
8 "github.com/MichaelMure/git-bug/input"
9 "github.com/spf13/cobra"
10)
11
12var (
13 titleEditTitle string
14)
15
16func runTitleEdit(cmd *cobra.Command, args []string) error {
17 backend, err := cache.NewRepoCache(repo)
18 if err != nil {
19 return err
20 }
21 defer backend.Close()
22
23 b, args, err := _select.ResolveBug(backend, args)
24 if err != nil {
25 return err
26 }
27
28 snap := b.Snapshot()
29
30 if titleEditTitle == "" {
31 titleEditTitle, err = input.BugTitleEditorInput(repo, snap.Title)
32 if err == input.ErrEmptyTitle {
33 fmt.Println("Empty title, aborting.")
34 return nil
35 }
36 if err != nil {
37 return err
38 }
39 }
40
41 err = b.SetTitle(titleEditTitle)
42 if err != nil {
43 return err
44 }
45
46 return b.Commit()
47}
48
49var titleEditCmd = &cobra.Command{
50 Use: "edit [<id>]",
51 Short: "Edit a bug title",
52 RunE: runTitleEdit,
53}
54
55func init() {
56 titleCmd.AddCommand(titleEditCmd)
57
58 titleEditCmd.Flags().SortFlags = false
59
60 titleEditCmd.Flags().StringVarP(&titleEditTitle, "title", "t", "",
61 "Provide a title to describe the issue",
62 )
63}