2018-09-18 14:17:39 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2019-11-03 16:00:35 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2020-07-28 21:24:24 +03:00
|
|
|
_select "github.com/MichaelMure/git-bug/commands/select"
|
2018-09-18 14:17:39 +03:00
|
|
|
)
|
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func newSelectCommand() *cobra.Command {
|
|
|
|
env := newEnv()
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
2020-07-28 21:24:24 +03:00
|
|
|
Use: "select ID",
|
2020-06-28 19:26:29 +03:00
|
|
|
Short: "Select a bug for implicit use in future commands.",
|
|
|
|
Example: `git bug select 2f15
|
|
|
|
git bug comment
|
|
|
|
git bug status
|
|
|
|
`,
|
|
|
|
Long: `Select a bug for implicit use in future commands.
|
|
|
|
|
2020-07-28 21:24:24 +03:00
|
|
|
This command allows you to omit any bug ID argument, for example:
|
2020-06-28 19:26:29 +03:00
|
|
|
git bug show
|
|
|
|
instead of
|
|
|
|
git bug show 2f153ca
|
|
|
|
|
|
|
|
The complementary command is "git bug deselect" performing the opposite operation.
|
|
|
|
`,
|
2020-06-28 20:09:32 +03:00
|
|
|
PreRunE: loadBackend(env),
|
|
|
|
PostRunE: closeBackend(env),
|
2020-06-28 19:26:29 +03:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runSelect(env, args)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSelect(env *Env, args []string) error {
|
2018-09-18 14:17:39 +03:00
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("You must provide a bug id")
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := args[0]
|
|
|
|
|
2020-06-28 20:09:32 +03:00
|
|
|
b, err := env.backend.ResolveBugPrefix(prefix)
|
2018-09-18 14:17:39 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:09:32 +03:00
|
|
|
err = _select.Select(env.backend, b.Id())
|
2018-09-26 17:49:42 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-18 14:17:39 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
env.out.Printf("selected bug %s: %s\n", b.Id().Human(), b.Snapshot().Title)
|
2018-09-18 14:17:39 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|