Merge pull request #680 from ptsilva/enable-envs-tile38-cli

add hostname, port, output, and password env variables to tile38-cli
This commit is contained in:
Josh Baker 2023-05-06 06:27:20 -07:00 committed by GitHub
commit 7d052273c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -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 == "" {