mirror of https://github.com/tidwall/tile38.git
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:
commit
7d052273c4
|
@ -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 == "" {
|
||||
|
|
Loading…
Reference in New Issue