add hostname, port, output, and password env variables to tile38-cli

This commit is contained in:
Paulo Silva 2023-04-23 02:06:08 -03:00
parent dbd565d361
commit eb1b1aa167
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 == "" {