feat: add app config command

This commit is contained in:
decentral1se 2021-08-29 10:45:49 +02:00
parent 0825321b26
commit acca710a5a
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 46 additions and 3 deletions

View File

@ -18,7 +18,7 @@
- [ ] `deploy` (WIP: decentral1se) - [ ] `deploy` (WIP: decentral1se)
- [x] `check` - [x] `check`
- [x] `version` - [x] `version`
- [ ] `config` (WIP: decentral1se) - [x] `config`
- [ ] `cp` - [ ] `cp`
- [ ] `logs` - [ ] `logs`
- [x] `ps` - [x] `ps`

View File

@ -1,7 +1,50 @@
package app package app
import "github.com/urfave/cli/v2" import (
"errors"
"os"
"os/exec"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/config"
"github.com/AlecAivazis/survey/v2"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var appConfigCommand = &cli.Command{ var appConfigCommand = &cli.Command{
Name: "config", Name: "config",
Usage: "edit app environment config",
Action: func(c *cli.Context) error {
appName := c.Args().First()
if appName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided"))
}
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)
}
}
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
cmd := exec.Command(ed, appFiles[appName].Path)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
logrus.Fatal(err)
}
return nil
},
} }