git-ea/cmd/ide.go

45 lines
892 B
Go
Raw Permalink Normal View History

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)
return exec.Command("nvim", path).Start()
},
}
}