Every `:report` subcommand now recognizes `--global` as a scope selector that limits the report to globally-configured properties, including in JSON form via `--global --format json`. Previously this combination was rejected because `--global` was treated as an info flag, conflicting with `--format`. The shared `common.ParseReportArgs` helper now returns a `ReportArgs` struct exposing the parsed scope; each Go and bash report selects a global-only flag map when scope is global, and skips per-app verification.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
"github.com/dokku/dokku/plugins/ports"
|
|
|
|
flag "github.com/spf13/pflag"
|
|
)
|
|
|
|
// main entrypoint to all subcommands
|
|
func main() {
|
|
parts := strings.Split(os.Args[0], "/")
|
|
subcommand := parts[len(parts)-1]
|
|
|
|
var err error
|
|
switch subcommand {
|
|
case "list":
|
|
args := flag.NewFlagSet("ports:list", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
err = ports.CommandList(appName)
|
|
case "add":
|
|
args := flag.NewFlagSet("ports:add", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
_, portMaps := common.ShiftString(args.Args())
|
|
err = ports.CommandAdd(appName, portMaps)
|
|
case "clear":
|
|
args := flag.NewFlagSet("ports:clear", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
err = ports.CommandClear(appName)
|
|
case "remove":
|
|
args := flag.NewFlagSet("ports:remove", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
_, portMaps := common.ShiftString(args.Args())
|
|
err = ports.CommandRemove(appName, portMaps)
|
|
case "set":
|
|
args := flag.NewFlagSet("ports:set", flag.ExitOnError)
|
|
args.Parse(os.Args[2:])
|
|
appName := args.Arg(0)
|
|
_, portMaps := common.ShiftString(args.Args())
|
|
err = ports.CommandSet(appName, portMaps)
|
|
case "report":
|
|
args := flag.NewFlagSet("ports:report", flag.ExitOnError)
|
|
format := args.String("format", "stdout", "format: [ stdout | json ]")
|
|
reportArgs, flagErr := common.ParseReportArgs("ports", os.Args[2:])
|
|
if flagErr == nil {
|
|
args.Parse(reportArgs.OSArgs)
|
|
appName := args.Arg(0)
|
|
if reportArgs.IsGlobal {
|
|
appName = "--global"
|
|
}
|
|
err = ports.CommandReport(appName, *format, reportArgs.InfoFlag)
|
|
}
|
|
default:
|
|
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
|
|
}
|
|
|
|
if err != nil {
|
|
common.LogFailWithError(err)
|
|
}
|
|
}
|