From eb1b1aa16728ddbcdcd36edb881eba59d1ddbbd8 Mon Sep 17 00:00:00 2001 From: Paulo Silva <05.paulotarso@gmail.com> Date: Sun, 23 Apr 2023 02:06:08 -0300 Subject: [PATCH] add hostname, port, output, and password env variables to tile38-cli --- cmd/tile38-cli/main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cmd/tile38-cli/main.go b/cmd/tile38-cli/main.go index bda428f1..f8741d5c 100644 --- a/cmd/tile38-cli/main.go +++ b/cmd/tile38-cli/main.go @@ -22,6 +22,14 @@ import ( "github.com/tidwall/tile38/core" ) +func getEnv(name string, defaultValue string) string { + val, exists := os.LookupEnv(name) + if !exists { + return defaultValue + } + return val +} + func userHomeDir() string { if runtime.GOOS == "windows" { home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") @@ -83,6 +91,17 @@ func parseArgs() bool { } }() + hostname = getEnv("TILE38_HOSTNAME", hostname) + output = getEnv("TILE38_OUTPUT", output) + portStr := getEnv("TILE38_PORT", "") + + if portStr != "" { + tempPort, err := strconv.Atoi(portStr) + if err == nil { + port = tempPort + } + } + args := os.Args[1:] readArg := func(arg string) string { if len(args) == 0 { @@ -286,7 +305,15 @@ func main() { f.Close() } }() + + password := getEnv("TILE38_PASSWORD", "") + + if conn != nil && password != "" { + conn.Do(fmt.Sprintf("auth %s", password)) + } + for { + var command string var err error if oneCommand == "" {