2022-09-04 02:06:06 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Handler) IDE() *ffcli.Command {
|
|
|
|
fs := flag.NewFlagSet("ide", flag.ContinueOnError)
|
|
|
|
return &ffcli.Command{
|
|
|
|
Name: "ide",
|
|
|
|
FlagSet: fs,
|
|
|
|
ShortUsage: "ide <branch>",
|
|
|
|
ShortHelp: "ide starts an IDE for `branch`",
|
|
|
|
Exec: func(ctx context.Context, args []string) error {
|
|
|
|
if err := h.checkInit(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var branch string
|
|
|
|
if len(args) > 0 {
|
|
|
|
branch = args[0]
|
|
|
|
} else {
|
|
|
|
opts, err := h.Config.Branches()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := survey.AskOne(&survey.Select{
|
|
|
|
Message: "Branch to open",
|
|
|
|
Options: opts,
|
|
|
|
}, &branch); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path := h.Config.WorkspaceBranch(branch)
|
2022-09-07 20:34:58 +00:00
|
|
|
return exec.Command("nvim", path).Start()
|
2022-09-04 02:06:06 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|