feat: add pre-parsed json string version of port mappings
This commit is contained in:
1 parent
491fae6c00
commit
3f13949337
1 file changed
+23
-2
+23
-2
@@ -1,6 +1,7 @@
|
|||||||
package ports
|
package ports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
@@ -19,8 +20,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|||||||
flags = map[string]common.ReportFunc{}
|
flags = map[string]common.ReportFunc{}
|
||||||
} else {
|
} else {
|
||||||
flags = map[string]common.ReportFunc{
|
flags = map[string]common.ReportFunc{
|
||||||
"--ports-map": reportPortMap,
|
"--ports-map": reportPortMap,
|
||||||
"--ports-map-detected": reportPortMapDetected,
|
"--ports-map-json": reportPortMapAsJSON,
|
||||||
|
"--ports-map-detected": reportPortMapDetected,
|
||||||
|
"--ports-map-detected-json": reportPortMapDetectedAsJSON,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +55,15 @@ func reportPortMap(appName string) string {
|
|||||||
return strings.Join(portMaps, " ")
|
return strings.Join(portMaps, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportPortMapAsJSON(appName string) string {
|
||||||
|
json, err := json.Marshal(getPortMaps(appName))
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(json)
|
||||||
|
}
|
||||||
|
|
||||||
func reportPortMapDetected(appName string) string {
|
func reportPortMapDetected(appName string) string {
|
||||||
var portMaps []string
|
var portMaps []string
|
||||||
for _, portMap := range getDetectedPortMaps(appName) {
|
for _, portMap := range getDetectedPortMaps(appName) {
|
||||||
@@ -60,3 +72,12 @@ func reportPortMapDetected(appName string) string {
|
|||||||
|
|
||||||
return strings.Join(portMaps, " ")
|
return strings.Join(portMaps, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportPortMapDetectedAsJSON(appName string) string {
|
||||||
|
json, err := json.Marshal(getDetectedPortMaps(appName))
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(json)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user