decentral1se
66aeeee768
All checks were successful
continuous-integration/drone/push Build is passing
Closes coop-cloud/organising#161.
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var appConfigCommand = &cli.Command{
|
|
Name: "config",
|
|
Aliases: []string{"c"},
|
|
Usage: "Edit app config",
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
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, app.Path)
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
if err := cmd.Run(); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
BashComplete: func(c *cli.Context) {
|
|
appNames, err := config.GetAppNames()
|
|
if err != nil {
|
|
logrus.Warn(err)
|
|
}
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
for _, a := range appNames {
|
|
fmt.Println(a)
|
|
}
|
|
},
|
|
}
|