Files
dokku/plugins/resource/subcommands.go
Jose Diaz-Gonzalez 94aa67d494 feat: simplify flag parsing in resource plugin
Commands should be written such that they take arguments as is.
2020-05-29 01:59:50 -04:00

70 lines
1.6 KiB
Go

package resource
import (
"errors"
"strings"
"github.com/dokku/dokku/plugins/common"
)
// CommandLimit implements resource:limit
func CommandLimit(appName string, processType string, r Resource) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
return setResourceType(appName, processType, r, "limit")
}
// CommandLimitClear implements resource:limit-clear
func CommandLimitClear(appName string, processType string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
clearByResourceType(appName, processType, "limit")
return nil
}
// CommandReport displays a resource report for one or more apps
func CommandReport(appName string, infoFlag string) error {
if strings.HasPrefix(appName, "--") {
infoFlag = appName
appName = ""
}
if len(appName) == 0 {
apps, err := common.DokkuApps()
if err != nil {
return err
}
for _, appName := range apps {
if err := ReportSingleApp(appName, infoFlag); err != nil {
return err
}
}
return nil
}
return ReportSingleApp(appName, infoFlag)
}
// CommandReserve implements resource:reserve
func CommandReserve(appName string, processType string, r Resource) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
return setResourceType(appName, processType, r, "reserve")
}
// CommandReserveClear implements resource:reserve-clear
func CommandReserveClear(appName string, processType string) error {
if appName == "" {
return errors.New("Please specify an app to run the command on")
}
clearByResourceType(appName, processType, "reserve")
return nil
}