2018-09-18 14:17:39 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2019-11-03 16:00:35 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-09-18 14:17:39 +03:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-08-12 17:12:14 +03:00
|
|
|
fmt.Printf("selected bug %s: %s\n", b.Id().Human(), b.Snapshot().Title)
|
2018-09-18 14:17:39 +03:00
|
|
|
|
|
|
|
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
|
2019-03-23 19:59:40 +03:00
|
|
|
`,
|
|
|
|
Long: `Select a bug for implicit use in future commands.
|
|
|
|
|
2019-03-23 21:03:39 +03:00
|
|
|
This command allows you to omit any bug <id> argument, for example:
|
|
|
|
git bug show
|
|
|
|
instead of
|
|
|
|
git bug show 2f153ca
|
2019-03-23 19:59:40 +03:00
|
|
|
|
|
|
|
The complementary command is "git bug deselect" performing the opposite operation.
|
2018-09-18 14:17:39 +03:00
|
|
|
`,
|
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
|
|
|
|
}
|