feat: support service completion
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Closes coop-cloud/organising#165.
This commit is contained in:
parent
6c9bb89a10
commit
6794236b77
|
@ -102,15 +102,24 @@ var appRunCommand = &cli.Command{
|
|||
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)
|
||||
switch c.NArg() {
|
||||
case 0:
|
||||
appNames, err := config.GetAppNames()
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
for _, a := range appNames {
|
||||
fmt.Println(a)
|
||||
}
|
||||
case 1:
|
||||
appName := c.Args().First()
|
||||
serviceNames, err := config.GetAppServiceNames(appName)
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
for _, s := range serviceNames {
|
||||
fmt.Println(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -190,6 +190,38 @@ func GetApps(appFiles AppFiles) ([]App, error) {
|
|||
return apps, nil
|
||||
}
|
||||
|
||||
// GetAppServiceNames retrieves a list of app service names.
|
||||
func GetAppServiceNames(appName string) ([]string, error) {
|
||||
var serviceNames []string
|
||||
|
||||
appFiles, err := LoadAppFiles("")
|
||||
if err != nil {
|
||||
return serviceNames, err
|
||||
}
|
||||
|
||||
app, err := GetApp(appFiles, appName)
|
||||
if err != nil {
|
||||
return serviceNames, err
|
||||
}
|
||||
|
||||
composeFiles, err := GetAppComposeFiles(app.Type, app.Env)
|
||||
if err != nil {
|
||||
return serviceNames, err
|
||||
}
|
||||
|
||||
opts := stack.Deploy{Composefiles: composeFiles}
|
||||
compose, err := GetAppComposeConfig(app.Type, opts, app.Env)
|
||||
if err != nil {
|
||||
return serviceNames, err
|
||||
}
|
||||
|
||||
for _, service := range compose.Services {
|
||||
serviceNames = append(serviceNames, service.Name)
|
||||
}
|
||||
|
||||
return serviceNames, nil
|
||||
}
|
||||
|
||||
// GetAppNames retrieves a list of app names.
|
||||
func GetAppNames() ([]string, error) {
|
||||
var appNames []string
|
||||
|
|
Loading…
Reference in New Issue