feat: allow formatting :report command output as json
This commit is contained in:
@@ -18,7 +18,7 @@ type Resource struct {
|
||||
}
|
||||
|
||||
// ReportSingleApp is an internal function that displays the resource report for one or more apps
|
||||
func ReportSingleApp(appName, infoFlag string) error {
|
||||
func ReportSingleApp(appName, format, infoFlag string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func ReportSingleApp(appName, infoFlag string) error {
|
||||
|
||||
trimPrefix := true
|
||||
uppercaseFirstCharacter := false
|
||||
return common.ReportSingleApp("resource", appName, infoFlag, flags, flagKeys, trimPrefix, uppercaseFirstCharacter)
|
||||
return common.ReportSingleApp("resource", appName, infoFlag, flags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
||||
}
|
||||
|
||||
// GetResourceValue fetches a single value for a given app/process/request/key combination
|
||||
|
||||
@@ -50,11 +50,12 @@ func main() {
|
||||
err = resource.CommandLimitClear(appName, *processType)
|
||||
case "report":
|
||||
args := flag.NewFlagSet("resource:report", flag.ExitOnError)
|
||||
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
||||
osArgs, infoFlag, flagErr := common.ParseReportArgs("resource", os.Args[2:])
|
||||
if flagErr == nil {
|
||||
args.Parse(osArgs)
|
||||
appName := args.Arg(0)
|
||||
err = resource.CommandReport(appName, infoFlag)
|
||||
err = resource.CommandReport(appName, *format, infoFlag)
|
||||
}
|
||||
case "reserve":
|
||||
args := flag.NewFlagSet("resource:reserve", flag.ExitOnError)
|
||||
|
||||
@@ -37,7 +37,7 @@ func main() {
|
||||
err = resource.TriggerPostDelete(appName)
|
||||
case "report":
|
||||
appName := flag.Arg(0)
|
||||
err = resource.ReportSingleApp(appName, "")
|
||||
err = resource.ReportSingleApp(appName, "", "")
|
||||
case "resource-get-property":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
|
||||
@@ -24,21 +24,21 @@ func CommandLimitClear(appName string, processType string) error {
|
||||
}
|
||||
|
||||
// CommandReport displays a resource report for one or more apps
|
||||
func CommandReport(appName string, infoFlag string) error {
|
||||
func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
if err := ReportSingleApp(appName, infoFlag); err != nil {
|
||||
if err := ReportSingleApp(appName, format, infoFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return ReportSingleApp(appName, infoFlag)
|
||||
return ReportSingleApp(appName, format, infoFlag)
|
||||
}
|
||||
|
||||
// CommandReserve implements resource:reserve
|
||||
|
||||
Reference in New Issue
Block a user