1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/MichaelMure/git-bug/commands/select"
9 "github.com/spf13/cobra"
10)
11
12func runSelect(cmd *cobra.Command, args []string) error {
13 if len(args) == 0 {
14 return errors.New("You must provide a bug id")
15 }
16
17 backend, err := cache.NewRepoCache(repo)
18 if err != nil {
19 return err
20 }
21 defer backend.Close()
22
23 prefix := args[0]
24
25 b, err := backend.ResolveBugPrefix(prefix)
26 if err != nil {
27 return err
28 }
29
30 _select.Select(backend, b.Id())
31
32 fmt.Printf("selected bug %s: %s\n", b.HumanId(), b.Snapshot().Title)
33
34 return nil
35}
36
37var selectCmd = &cobra.Command{
38 Use: "select <id>",
39 Short: "Select a bug for implicit use in future commands",
40 Example: `git bug select 2f15
41git bug comment
42git bug status
43`,
44 RunE: runSelect,
45}
46
47func init() {
48 RootCmd.AddCommand(selectCmd)
49 selectCmd.Flags().SortFlags = false
50}