Merge pull request 'feat: auto-complete app and recipe names' (#89) from knoflook/abra:main into main
continuous-integration/drone/push Build is passing Details

Reviewed-on: #89
This commit is contained in:
decentral1se 2021-09-08 12:16:41 +00:00
commit e114b2a939
16 changed files with 205 additions and 1 deletions

View File

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

View File

@ -1,6 +1,7 @@
package app
import (
"fmt"
"os"
"path"
"strings"
@ -48,4 +49,16 @@ var appCheckCommand = &cli.Command{
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}

View File

@ -1,10 +1,12 @@
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"
@ -38,4 +40,16 @@ var appConfigCommand = &cli.Command{
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}

View File

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

View File

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

View File

@ -9,6 +9,7 @@ import (
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
dockerClient "github.com/docker/docker/client"
@ -109,4 +110,16 @@ var appLogsCommand = &cli.Command{
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
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>",
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.

View File

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

View File

@ -1,10 +1,27 @@
package app
import "github.com/urfave/cli/v2"
import (
"fmt"
"coopcloud.tech/abra/pkg/config"
"github.com/urfave/cli/v2"
)
var appRollbackCommand = &cli.Command{
Name: "rollback",
Usage: "Roll an app back to a previous version",
Aliases: []string{"b"},
ArgsUsage: "[<version>]",
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}

View File

@ -10,6 +10,7 @@ import (
abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/secret"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
@ -234,6 +235,18 @@ var appSecretLsCommand = &cli.Command{
table.Render()
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}
var appSecretCommand = &cli.Command{

View File

@ -2,10 +2,12 @@ package app
import (
"context"
"fmt"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
stack "coopcloud.tech/abra/pkg/client/stack"
"coopcloud.tech/abra/pkg/config"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -35,4 +37,16 @@ volumes as eligiblef or pruning once undeployed.
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}

View File

@ -104,4 +104,16 @@ var appVersionCommand = &cli.Command{
table.Render()
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
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 (
"context"
"fmt"
abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/AlecAivazis/survey/v2"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@ -81,6 +83,18 @@ var appVolumeRemoveCommand = &cli.Command{
return nil
},
BashComplete: func(c *cli.Context) {
appNames, err := config.GetAppNames()
if err != nil {
return
}
if c.NArg() > 0 {
return
}
for _, a := range appNames {
fmt.Println(a)
}
},
}
var appVolumeCommand = &cli.Command{

View File

@ -7,6 +7,7 @@ import (
"coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/catalogue"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/tagcmp"
"github.com/docker/distribution/reference"
@ -90,4 +91,16 @@ var recipeLintCommand = &cli.Command{
return nil
},
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)
}
},
}

View File

@ -177,6 +177,24 @@ func GetApps(appFiles AppFiles) ([]App, error) {
return apps, nil
}
func GetAppNames() ([]string, error) {
appFiles, err := LoadAppFiles("")
if err != nil {
return []string{}, err
}
apps, err := GetApps(appFiles)
if err != nil {
return []string{}, err
}
var appNames []string
for _, app := range apps {
appNames = append(appNames, app.Name)
}
return appNames, nil
}
// CopyAppEnvSample copies the example env file for the app into the users env files
func CopyAppEnvSample(appType, appName, server string) error {
envSamplePath := path.Join(ABRA_DIR, "apps", appType, ".env.sample")