feat: add --format json support to apps:list
The `apps:list` command now accepts a `--format` flag that defaults to `stdout` and can be set to `json` to emit the app names as a JSON array, matching the JSON output the `:report` subcommands already provide. When no apps exist, the JSON output is an empty array.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package apps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -98,9 +99,26 @@ func CommandExists(appName string) error {
|
||||
}
|
||||
|
||||
// CommandList lists all apps
|
||||
func CommandList() error {
|
||||
common.LogInfo2Quiet("My Apps")
|
||||
func CommandList(format string) error {
|
||||
apps, err := common.DokkuApps()
|
||||
|
||||
if format == "json" {
|
||||
if err != nil && !errors.Is(err, common.NoAppsExist) {
|
||||
return err
|
||||
}
|
||||
|
||||
appList := []string{}
|
||||
appList = append(appList, apps...)
|
||||
out, err := json.Marshal(appList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
common.Log(string(out))
|
||||
return nil
|
||||
}
|
||||
|
||||
common.LogInfo2Quiet("My Apps")
|
||||
if err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user