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:
Jose Diaz-Gonzalez
2026-07-06 11:50:56 -04:00
parent ce69ca76ad
commit 21c27e99cc
5 changed files with 67 additions and 6 deletions

View File

@@ -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