mirror of
https://github.com/dokku/dokku.git
synced 2026-02-24 04:00:36 +01:00
fix: correct the report output
This commit is contained in:
37
plugins/storage/report.go
Normal file
37
plugins/storage/report.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package storage
|
||||
|
||||
import "github.com/dokku/dokku/plugins/common"
|
||||
|
||||
func ReportSingleApp(appName string, infoFlag string, format string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
flags := map[string]common.ReportFunc{
|
||||
"--storage-build-mounts": reportBuildMounts,
|
||||
"--storage-deploy-mounts": reportDeployMounts,
|
||||
"--storage-run-mounts": reportRunMounts,
|
||||
}
|
||||
|
||||
flagKeys := []string{}
|
||||
for flagKey := range flags {
|
||||
flagKeys = append(flagKeys, flagKey)
|
||||
}
|
||||
|
||||
trimPrefix := false
|
||||
uppercaseFirstCharacter := true
|
||||
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
||||
return common.ReportSingleApp("storage", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
||||
}
|
||||
|
||||
func reportBuildMounts(appName string) string {
|
||||
return GetBindMountsForDisplay(appName, "build")
|
||||
}
|
||||
|
||||
func reportDeployMounts(appName string) string {
|
||||
return GetBindMountsForDisplay(appName, "deploy")
|
||||
}
|
||||
|
||||
func reportRunMounts(appName string) string {
|
||||
return GetBindMountsForDisplay(appName, "run")
|
||||
}
|
||||
@@ -38,23 +38,13 @@ func main() {
|
||||
mountPath := args.Arg(1)
|
||||
err = storage.CommandMount(appName, mountPath)
|
||||
case "report":
|
||||
args := flag.NewFlagSet("storage:report", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "--format: output format (stdout, json)")
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
osArgs, infoFlag, parseErr := common.ParseReportArgs("storage", args.Args())
|
||||
if parseErr != nil {
|
||||
err = parseErr
|
||||
} else {
|
||||
appName := ""
|
||||
if len(osArgs) > 0 {
|
||||
appName = osArgs[0]
|
||||
}
|
||||
if *format == "stdout" {
|
||||
err = storage.CommandReport(appName, infoFlag)
|
||||
} else {
|
||||
err = storage.CommandReportSingleApp(appName, infoFlag, *format)
|
||||
}
|
||||
args := flag.NewFlagSet("scheduler-k3s:report", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
||||
osArgs, infoFlag, flagErr := common.ParseReportArgs("scheduler-k3s", os.Args[2:])
|
||||
if flagErr == nil {
|
||||
args.Parse(osArgs)
|
||||
appName := args.Arg(0)
|
||||
err = storage.CommandReport(appName, *format, infoFlag)
|
||||
}
|
||||
case "unmount":
|
||||
args := flag.NewFlagSet("storage:unmount", flag.ExitOnError)
|
||||
|
||||
@@ -197,45 +197,23 @@ func CommandList(appName string, format string) error {
|
||||
}
|
||||
|
||||
// CommandReport displays a storage report for one or more apps
|
||||
func CommandReport(appName string, infoFlag string) error {
|
||||
func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if appName == "" {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
if errors.Is(err, common.NoAppsExist) {
|
||||
common.LogWarn(err.Error())
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
for _, app := range apps {
|
||||
if err := reportSingle(app, infoFlag, "stdout"); err != nil {
|
||||
if err := ReportSingleApp(app, format, infoFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return reportSingle(appName, infoFlag, "stdout")
|
||||
}
|
||||
|
||||
// CommandReportSingleApp displays a storage report for a single app with format support
|
||||
func CommandReportSingleApp(appName string, infoFlag string, format string) error {
|
||||
return reportSingle(appName, infoFlag, format)
|
||||
}
|
||||
|
||||
func reportSingle(appName string, infoFlag string, format string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
infoFlags := map[string]string{
|
||||
"--storage-build-mounts": GetBindMountsForDisplay(appName, "build"),
|
||||
"--storage-deploy-mounts": GetBindMountsForDisplay(appName, "deploy"),
|
||||
"--storage-run-mounts": GetBindMountsForDisplay(appName, "run"),
|
||||
}
|
||||
|
||||
infoFlagKeys := []string{
|
||||
"--storage-build-mounts",
|
||||
"--storage-deploy-mounts",
|
||||
"--storage-run-mounts",
|
||||
}
|
||||
|
||||
return common.ReportSingleApp("storage", appName, infoFlag, infoFlags, infoFlagKeys, format, true, true)
|
||||
return ReportSingleApp(appName, format, infoFlag)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user