Previously, golang plugins would omit subcommands for 'dokku help --all', meaning they could not be introspected upon by outside tooling.
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
columnize "github.com/ryanuber/columnize"
|
|
)
|
|
|
|
const (
|
|
helpHeader = `Usage: dokku network[:COMMAND]
|
|
|
|
Manages network settings for an app
|
|
|
|
Additional commands:`
|
|
|
|
helpContent = `
|
|
network:report [<app>] [<flag>], Displays a network report for one or more apps
|
|
network:rebuild <app>, Rebuilds network settings for an app
|
|
network:rebuildall, Rebuild network settings for all apps
|
|
network:set <app> <property> (<value>), Set or clear a network property for an app
|
|
`
|
|
)
|
|
|
|
func main() {
|
|
flag.Usage = usage
|
|
flag.Parse()
|
|
|
|
cmd := flag.Arg(0)
|
|
switch cmd {
|
|
case "network", "network:help":
|
|
usage()
|
|
case "help":
|
|
command := common.NewShellCmd(fmt.Sprintf("ps -o command= %d", os.Getppid()))
|
|
command.ShowOutput = false
|
|
output, err := command.Output()
|
|
|
|
if err == nil && strings.Contains(string(output), "--all") {
|
|
fmt.Println(helpContent)
|
|
} else {
|
|
fmt.Print("\n network, Manages network settings 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() {
|
|
fmt.Println(helpHeader)
|
|
config := columnize.DefaultConfig()
|
|
config.Delim = ","
|
|
config.Prefix = " "
|
|
config.Empty = ""
|
|
content := strings.Split(helpContent, "\n")[1:]
|
|
fmt.Println(columnize.Format(content, config))
|
|
}
|