fix wrong way to take user and host from env (#552)

This commit is contained in:
Minghe
2020-06-28 00:27:54 +08:00
committed by GitHub
parent ba43561f40
commit 0f4120c2c8
2 changed files with 13 additions and 6 deletions

2
fx.go
View File

@@ -19,7 +19,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)
const version = "0.9.43"
const version = "0.9.44"
func init() {
go checkForUpdate()

View File

@@ -24,10 +24,8 @@ func set(ctx context.Contexter, cli *cli.Context, fields []argsField) error {
if len(addr) != 2 {
return fmt.Errorf("invalid host information, should be format of <user>@<ip>")
}
user := addr[0]
ip := addr[1]
ctx.Set("host", ip)
ctx.Set("user", user)
ctx.Set("host", addr[1])
ctx.Set("user", addr[0])
} else {
ctx.Set(f.Name, cli.String(f.Name))
}
@@ -38,7 +36,16 @@ func set(ctx context.Contexter, cli *cli.Context, fields []argsField) error {
}
if f.Env != "" && os.Getenv(f.Env) != "" {
ctx.Set(f.Name, os.Getenv(f.Env))
if f.Name == "host" {
info := strings.Split(os.Getenv(f.Env), "@")
if len(info) != 2 {
return fmt.Errorf("invalid host information, should be format of <user>@<ip>")
}
ctx.Set("host", info[1])
ctx.Set("user", info[0])
} else {
ctx.Set(f.Name, os.Getenv(f.Env))
}
}
}
return nil