2018-09-18 14:17:39 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
|
|
|
"github.com/MichaelMure/git-bug/commands/select"
|
2018-10-25 00:36:39 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
2018-09-18 14:17:39 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func runSelect(cmd *cobra.Command, args []string) error {
|
|
|
|
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()
|
2018-10-25 00:36:39 +03:00
|
|
|
interrupt.RegisterCleaner(backend.Close)
|
2018-09-18 14:17:39 +03:00
|
|
|
|
|
|
|
prefix := args[0]
|
|
|
|
|
|
|
|
b, err := backend.ResolveBugPrefix(prefix)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-26 17:49:42 +03:00
|
|
|
err = _select.Select(backend, b.Id())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-18 14:17:39 +03:00
|
|
|
|
|
|
|
fmt.Printf("selected bug %s: %s\n", b.HumanId(), b.Snapshot().Title)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var selectCmd = &cobra.Command{
|
2018-09-18 14:28:01 +03:00
|
|
|
Use: "select <id>",
|
2019-02-24 16:46:08 +03:00
|
|
|
Short: "Select a bug for implicit use in future commands.",
|
2018-09-18 14:17:39 +03:00
|
|
|
Example: `git bug select 2f15
|
|
|
|
git bug comment
|
|
|
|
git bug status
|
|
|
|
`,
|
2018-10-17 21:38:10 +03:00
|
|
|
PreRunE: loadRepo,
|
|
|
|
RunE: runSelect,
|
2018-09-18 14:17:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(selectCmd)
|
|
|
|
selectCmd.Flags().SortFlags = false
|
|
|
|
}
|