65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var appConfigCommand = cli.Command{
|
|
Name: "config",
|
|
Aliases: []string{"cfg"},
|
|
Usage: "Edit app config",
|
|
ArgsUsage: "<domain>",
|
|
Flags: []cli.Flag{
|
|
internal.DebugFlag,
|
|
},
|
|
Before: internal.SubCommandBefore,
|
|
BashComplete: autocomplete.AppNameComplete,
|
|
Action: func(c *cli.Context) error {
|
|
appName := c.Args().First()
|
|
|
|
if appName == "" {
|
|
internal.ShowSubcommandHelpAndError(c, errors.New("no app provided"))
|
|
}
|
|
|
|
files, err := config.LoadAppFiles("")
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
appFile, exists := files[appName]
|
|
if !exists {
|
|
logrus.Fatalf("cannot find app with name %s", appName)
|
|
}
|
|
|
|
ed, ok := os.LookupEnv("EDITOR")
|
|
if !ok {
|
|
edPrompt := &survey.Select{
|
|
Message: "Which editor do you wish to use?",
|
|
Options: []string{"vi", "vim", "nvim", "nano", "pico", "emacs"},
|
|
}
|
|
if err := survey.AskOne(edPrompt, &ed); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
|
|
cmd := exec.Command(ed, appFile.Path)
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
if err := cmd.Run(); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|