These were alpha prototypes and we'll reconsider once other layers of Abra are more stable.
85 lines
1.4 KiB
Go
85 lines
1.4 KiB
Go
package autocomplete
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"coopcloud.tech/abra/pkg/recipe"
|
|
"coopcloud.tech/abra/pkg/runtime"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
// AppNameComplete copletes app names.
|
|
func AppNameComplete(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)
|
|
}
|
|
}
|
|
|
|
// RecipeNameComplete completes recipe names.
|
|
func RecipeNameComplete(c *cli.Context) {
|
|
// defaults since we can't take arguments here... this means auto-completion
|
|
// of recipe names always access the network if e.g. the catalogue needs
|
|
// cloning / updating
|
|
conf := runtime.New()
|
|
|
|
catl, err := recipe.ReadRecipeCatalogue(conf)
|
|
if err != nil {
|
|
logrus.Warn(err)
|
|
}
|
|
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
|
|
for name := range catl {
|
|
fmt.Println(name)
|
|
}
|
|
}
|
|
|
|
// ServerNameComplete completes server names.
|
|
func ServerNameComplete(c *cli.Context) {
|
|
files, err := config.LoadAppFiles("")
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
|
|
for _, appFile := range files {
|
|
fmt.Println(appFile.Server)
|
|
}
|
|
}
|
|
|
|
// SubcommandComplete completes sub-commands.
|
|
func SubcommandComplete(c *cli.Context) {
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
|
|
subcmds := []string{
|
|
"app",
|
|
"autocomplete",
|
|
"catalogue",
|
|
"recipe",
|
|
"server",
|
|
"upgrade",
|
|
}
|
|
|
|
for _, cmd := range subcmds {
|
|
fmt.Println(cmd)
|
|
}
|
|
}
|