feat: auto-complete app and recipe names #89

Merged
decentral1se merged 3 commits from knoflook/abra:main into main 2021-09-08 12:16:42 +00:00
8 changed files with 120 additions and 0 deletions
Showing only changes of commit 4c216fdf40 - Show all commits

View File

@ -95,6 +95,7 @@ can take some time.
} }
table.Render() table.Render()
return nil return nil
}, },
} }

View File

@ -9,6 +9,7 @@ import (
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
dockerClient "github.com/docker/docker/client" dockerClient "github.com/docker/docker/client"
@ -109,4 +110,16 @@ var appLogsCommand = &cli.Command{
return nil return nil
}, },
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppsNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
} }

View File

@ -78,6 +78,18 @@ var appNewCommand = &cli.Command{
}, },
ArgsUsage: "<recipe>", ArgsUsage: "<recipe>",
Action: action, Action: action,
BashComplete: func(c *cli.Context) {
catl, err := catalogue.ReadRecipeCatalogue()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for name, _ := range catl {
fmt.Println(name)
}
},
} }
// getRecipeMeta retrieves the recipe metadata from the recipe catalogue. // getRecipeMeta retrieves the recipe metadata from the recipe catalogue.

View File

@ -2,11 +2,13 @@ package app
import ( import (
"context" "context"
"fmt"
"strings" "strings"
abraFormatter "coopcloud.tech/abra/cli/formatter" abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
@ -54,4 +56,16 @@ var appPsCommand = &cli.Command{
table.Render() table.Render()
return nil return nil
}, },
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppsNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
} }

View File

@ -155,4 +155,16 @@ var appRemoveCommand = &cli.Command{
return nil return nil
}, },
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppsNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
} }

View File

@ -2,10 +2,12 @@ package app
import ( import (
"context" "context"
"fmt"
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/client"
stack "coopcloud.tech/abra/pkg/client/stack" stack "coopcloud.tech/abra/pkg/client/stack"
"coopcloud.tech/abra/pkg/config"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -35,4 +37,16 @@ volumes as eligiblef or pruning once undeployed.
return nil return nil
}, },
BashComplete: func(c *cli.Context) {
appNames, err := config.GetDeployedApps()
knoflook marked this conversation as resolved Outdated

Given coop-cloud/abra#87 (comment) I guess we can just do config.GetAppsNames and call it a day?

Given https://git.coopcloud.tech/coop-cloud/abra/issues/87#issuecomment-8528 I guess we can just do `config.GetAppsNames` and call it a day?
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
} }

View File

@ -2,10 +2,12 @@ package app
import ( import (
"context" "context"
"fmt"
abraFormatter "coopcloud.tech/abra/cli/formatter" abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -81,6 +83,18 @@ var appVolumeRemoveCommand = &cli.Command{
return nil return nil
}, },
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppsNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
} }
var appVolumeCommand = &cli.Command{ var appVolumeCommand = &cli.Command{

View File

@ -177,6 +177,46 @@ func GetApps(appFiles AppFiles) ([]App, error) {
return apps, nil return apps, nil
} }
func GetAppsNames() ([]string, error) {
knoflook marked this conversation as resolved Outdated

Maybe a nitpick but GetAppNames is easier to say 😀 (ignore ofc if you don't mind it)

Maybe a nitpick but `GetAppNames` is easier to say 😀 (ignore ofc if you don't mind it)
appFiles, err := LoadAppFiles("")
if err != nil {
return nil, err
knoflook marked this conversation as resolved Outdated

return []string{}, err to pass an empty list and avoid nil errors somewhere else?

`return []string{}, err` to pass an empty list and avoid nil errors somewhere else?
}
apps, err := GetApps(appFiles)
if err != nil {
return nil, err
}
var appNames []string
for _, app := range apps {
appNames = append(appNames, app.Name)
}
return appNames, nil
}
func GetDeployedApps() ([]string, error) {
knoflook marked this conversation as resolved Outdated

Yeah I guess we don't need this now but maybe keep it?

idk, could also just end up lurking there without being used 🤔

Yeah I guess we don't need this now but maybe keep it? idk, could also just end up lurking there without being used 🤔

It's simple enought to rewrite so might as well get rid of it

It's simple enought to rewrite so might as well get rid of it
appFiles, err := LoadAppFiles("")
if err != nil {
return nil, err
}
apps, err := GetApps(appFiles)
if err != nil {
return nil, err
}
statuses, err := GetAppStatuses(appFiles)
var appNames []string
for _, app := range apps {
status := statuses[app.StackName()]
if status == "deployed" {
appNames = append(appNames, app.Name)
}
}
return appNames, nil
}
// CopyAppEnvSample copies the example env file for the app into the users env files // CopyAppEnvSample copies the example env file for the app into the users env files
func CopyAppEnvSample(appType, appName, server string) error { func CopyAppEnvSample(appType, appName, server string) error {
envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample") envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample")