Skip to content
This repository has been archived by the owner on Feb 27, 2018. It is now read-only.

Commit

Permalink
Don't mix unset and exports, and cater for spaces in the cert path
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
  • Loading branch information
SvenDowideit committed Mar 3, 2015
1 parent 0a3a250 commit 1c48ea8
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,14 @@ func checkEnvironment(socket, certPath string) bool {
}

func printExport(socket, certPath string) {
for name, value := range exports(socket, certPath) {
switch filepath.Base(os.Getenv("SHELL")) {
case "fish":
if value == "" {
fmt.Printf(" set -e %s\n", name)
} else {
fmt.Printf(" set -x %s %s\n", name, value)
}
default: // default command to export variables POSIX shells, like bash, zsh, etc.
if value == "" {
fmt.Printf(" unset %s\n", name)
} else {
fmt.Printf(" export %s=%s\n", name, value)
}
}
env := exports(socket, certPath)
switch filepath.Base(os.Getenv("SHELL")) {
case "fish":
fmt.Printf("set -x DOCKER_TLS_VERIFY %s\nset -x DOCKER_CERT_PATH %s\nset -x DOCKER_HOST %s\n",
env["DOCKER_TLS_VERIFY"], strings.Replace(env["DOCKER_CERT_PATH"], ` `, `\ `, -1), env["DOCKER_HOST"])
default:
fmt.Printf("export DOCKER_TLS_VERIFY=%s DOCKER_CERT_PATH=%s DOCKER_HOST=%s\n",
env["DOCKER_TLS_VERIFY"], strings.Replace(env["DOCKER_CERT_PATH"], ` `, `\ `, -1), env["DOCKER_HOST"])
}
}

Expand All @@ -225,7 +218,7 @@ func exports(socket, certPath string) map[string]string {
if certPath == "" {
out["DOCKER_TLS_VERIFY"] = ""
} else {
out["DOCKER_TLS_VERIFY"] = "1"
out["DOCKER_TLS_VERIFY"] = "yes"
}

return out
Expand Down

0 comments on commit 1c48ea8

Please sign in to comment.