Files
dokku/plugins/docker-options/report.go
Jose Diaz-Gonzalez 3bf6c72451 fix: align Go-plugin :report JSON keys with bash-strip convention
Every Go-implemented plugin's `:report --format json` now emits keys without the redundant `<plugin>-` head segment, matching the shape bash plugins have always emitted. The CLI flag names and `:set` semantics are unchanged. For backwards compatibility during the 0.38.x patch series, the legacy `<plugin>-<property>` keys are emitted side-by-side with the new keys, and a future major release will drop the legacy keys. `common.ReportSingleApp` is refactored to accept a `ReportSingleAppInput` struct with a `Validate()` method so the input is checked before any work runs, which also catches the latent `"docker options"` reportType bug at the API boundary.
2026-05-27 07:17:00 -04:00

82 lines
2.3 KiB
Go

package dockeroptions
import (
"fmt"
"strings"
"github.com/dokku/dokku/plugins/common"
)
// ReportSingleApp displays the docker options report for a single app.
// Default-scope options are reported under fixed keys for each phase.
// Process-scoped options surface as dynamic per-process keys, one per
// configured process+phase combination.
func ReportSingleApp(appName string, format string, infoFlag string) error {
if appName != "--global" {
if err := common.VerifyAppName(appName); err != nil {
return err
}
}
var flags map[string]common.ReportFunc
if appName == "--global" {
flags = map[string]common.ReportFunc{}
} else {
flags = map[string]common.ReportFunc{
"--docker-options-build": reportBuildOptions,
"--docker-options-deploy": reportDeployOptions,
"--docker-options-run": reportRunOptions,
}
}
processTypes, err := ListProcessTypesWithOptions(appName)
if err != nil {
return err
}
for _, processType := range processTypes {
processType := processType
flagName := fmt.Sprintf("--docker-options-deploy.%s", processType)
flags[flagName] = func(app string) string {
return joinProcessPhaseOptions(app, processType, "deploy")
}
}
flagKeys := []string{}
for flagKey := range flags {
flagKeys = append(flagKeys, flagKey)
}
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp(common.ReportSingleAppInput{
ReportType: "docker-options",
AppName: appName,
InfoFlag: infoFlag,
InfoFlags: infoFlags,
InfoFlagKeys: flagKeys,
Format: format,
TrimPrefix: true,
UppercaseFirstCharacter: true,
EmitLegacyPrefix: true,
})
}
func reportBuildOptions(appName string) string {
return joinProcessPhaseOptions(appName, DefaultProcessType, "build")
}
func reportDeployOptions(appName string) string {
return joinProcessPhaseOptions(appName, DefaultProcessType, "deploy")
}
func reportRunOptions(appName string) string {
return joinProcessPhaseOptions(appName, DefaultProcessType, "run")
}
func joinProcessPhaseOptions(appName, processType, phase string) string {
options, err := GetDockerOptionsForProcessPhase(appName, processType, phase)
if err != nil || len(options) == 0 {
return ""
}
return strings.Join(options, " ")
}