1package commands
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/pkg/errors"
8 "github.com/spf13/cobra"
9)
10
11func runTitle(cmd *cobra.Command, args []string) error {
12 var err error
13
14 if len(args) > 1 {
15 return errors.New("Only one bug id is supported")
16 }
17
18 if len(args) == 0 {
19 return errors.New("You must provide a bug id")
20 }
21
22 backend, err := cache.NewRepoCache(repo)
23 if err != nil {
24 return err
25 }
26 defer backend.Close()
27
28 prefix := args[0]
29
30 b, err := backend.ResolveBugPrefix(prefix)
31 if err != nil {
32 return err
33 }
34
35 snap := b.Snapshot()
36
37 fmt.Println(snap.Title)
38
39 return nil
40}
41
42var titleCmd = &cobra.Command{
43 Use: "title <id>",
44 Short: "Display a bug's title",
45 RunE: runTitle,
46}
47
48func init() {
49 RootCmd.AddCommand(titleCmd)
50
51 commentCmd.Flags().SortFlags = false
52}