refactor: move apps listing from common plugin to apps plugin
This helps centralize app-related listing fetching.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/clone subcommands/create subcommands/destroy subcommands/exists subcommands/list subcommands/lock subcommands/locked subcommands/rename subcommands/report subcommands/unlock
|
||||
TRIGGERS = triggers/app-create triggers/app-destroy triggers/app-exists triggers/app-maybe-create triggers/deploy-source-set triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
|
||||
TRIGGERS = triggers/app-create triggers/app-destroy triggers/app-exists triggers/app-list triggers/app-maybe-create triggers/deploy-source-set triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = apps
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package apps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultProperties is a map of all valid network properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
@@ -13,3 +21,30 @@ var (
|
||||
"deploy-source-metadata": true,
|
||||
}
|
||||
)
|
||||
|
||||
// DokkuApps returns a list of all local apps
|
||||
func DokkuApps() ([]string, error) {
|
||||
apps := []string{}
|
||||
dokkuRoot := common.MustGetEnv("DOKKU_ROOT")
|
||||
files, err := ioutil.ReadDir(dokkuRoot)
|
||||
if err != nil {
|
||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
appRoot := common.AppRoot(f.Name())
|
||||
if !common.DirectoryExists(appRoot) {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(f.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
apps = append(apps, f.Name())
|
||||
}
|
||||
|
||||
if len(apps) == 0 {
|
||||
return apps, fmt.Errorf("You haven't deployed any applications yet")
|
||||
}
|
||||
|
||||
return apps, nil
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ func main() {
|
||||
case "app-exists":
|
||||
appName := flag.Arg(0)
|
||||
err = apps.TriggerAppExists(appName)
|
||||
case "app-list":
|
||||
err = apps.TriggerAppList()
|
||||
case "app-maybe-create":
|
||||
appName := flag.Arg(0)
|
||||
err = apps.TriggerAppMaybeCreate(appName)
|
||||
|
||||
@@ -85,7 +85,7 @@ func CommandExists(appName string) error {
|
||||
// CommandList lists all apps
|
||||
func CommandList() error {
|
||||
common.LogInfo2Quiet("My Apps")
|
||||
apps, err := common.DokkuApps()
|
||||
apps, err := DokkuApps()
|
||||
if err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
@@ -177,7 +177,7 @@ func CommandRename(oldAppName string, newAppName string, skipDeploy bool) error
|
||||
// CommandReport displays an app report for one or more apps
|
||||
func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
apps, err := DokkuApps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,6 +21,16 @@ func TriggerAppExists(appName string) error {
|
||||
return appExists(appName)
|
||||
}
|
||||
|
||||
// TriggerAppList outputs each app name to stdout on a newline
|
||||
func TriggerAppList() error {
|
||||
apps, _ := DokkuApps()
|
||||
for _, app := range apps {
|
||||
common.Log(app)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerAppMaybeCreate is a trigger to allow gated app creation
|
||||
func TriggerAppMaybeCreate(appName string) error {
|
||||
return maybeCreateApp(appName)
|
||||
|
||||
Reference in New Issue
Block a user