Files
dokku/plugins/ports/src/commands/commands.go
T
Jose Diaz-Gonzalez 50239b056c fix: use new CallExecCommand when checking to see how help is being called
This is part of ongoing work to remove usage of the depreated NewShellCmd.
2024-02-12 00:55:16 -05:00

63 lines
1.6 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"strconv"
"strings"
"github.com/dokku/dokku/plugins/common"
)
const (
helpHeader = `Usage: dokku ports[:COMMAND]
Manage ports for an app
Additional commands:`
helpContent = `
ports:list <app>, List port mappings for app
ports:add <app> [<scheme>:<host-port>:<container-port>...], Add port mappings to an app
ports:clear <app>, Clear all port mappings for an app
ports:remove <app> [<host-port>|<scheme>:<host-port>:<container-port>...], Remove specific port mappings from an app
ports:set <app> [<scheme>:<host-port>:<container-port>...], Set port mappings for an app
ports:report [<app>] [<flag>], Displays a ports report for one or more apps
`
)
func main() {
flag.Usage = usage
flag.Parse()
cmd := flag.Arg(0)
switch cmd {
case "ports", "ports:help":
usage()
case "help":
result, err := common.CallExecCommand(common.ExecCommandInput{
Command: "ps",
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
CaptureOutput: true,
StreamStdio: false,
})
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
fmt.Println(helpContent)
} else {
fmt.Print("\n ports, Manage ports for an app\n")
}
default:
dokkuNotImplementExitCode, err := strconv.Atoi(os.Getenv("DOKKU_NOT_IMPLEMENTED_EXIT"))
if err != nil {
fmt.Println("failed to retrieve DOKKU_NOT_IMPLEMENTED_EXIT environment variable")
dokkuNotImplementExitCode = 10
}
os.Exit(dokkuNotImplementExitCode)
}
}
func usage() {
common.CommandUsage(helpHeader, helpContent)
}