powershell support

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett 2015-04-17 09:04:19 -04:00
parent 56ec00b3d2
commit cba15e843f
3 changed files with 21 additions and 2 deletions

View File

@ -228,6 +228,10 @@ var Commands = []cli.Command{
Name: "swarm", Name: "swarm",
Usage: "Display the Swarm config instead of the Docker daemon", Usage: "Display the Swarm config instead of the Docker daemon",
}, },
cli.StringFlag{
Name: "shell",
Usage: "Force environment to be configured for specified shell",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "unset, u", Name: "unset, u",
Usage: "Unset variables instead of setting them", Usage: "Unset variables instead of setting them",

View File

@ -14,7 +14,10 @@ import (
) )
func cmdEnv(c *cli.Context) { func cmdEnv(c *cli.Context) {
userShell := filepath.Base(os.Getenv("SHELL")) userShell := c.String("shell")
if userShell == "" {
userShell = filepath.Base(os.Getenv("SHELL"))
}
if c.Bool("unset") { if c.Bool("unset") {
switch userShell { switch userShell {
case "fish": case "fish":
@ -89,6 +92,9 @@ func cmdEnv(c *cli.Context) {
case "fish": case "fish":
fmt.Printf("set -x DOCKER_TLS_VERIFY 1;\nset -x DOCKER_CERT_PATH %q;\nset -x DOCKER_HOST %s;\n\n%s\n", fmt.Printf("set -x DOCKER_TLS_VERIFY 1;\nset -x DOCKER_CERT_PATH %q;\nset -x DOCKER_HOST %s;\n\n%s\n",
cfg.machineDir, dockerHost, usageHint) cfg.machineDir, dockerHost, usageHint)
case "powershell":
fmt.Printf("$env:DOCKER_TLS_VERIFY=1\n$env:DOCKER_CERT_PATH=\"%s\"\n$env:DOCKER_HOST=\"%s\"\n\n%s\n",
cfg.machineDir, dockerHost, usageHint)
default: default:
fmt.Printf("export DOCKER_TLS_VERIFY=1\nexport DOCKER_CERT_PATH=%q\nexport DOCKER_HOST=%s\n\n%s\n", fmt.Printf("export DOCKER_TLS_VERIFY=1\nexport DOCKER_CERT_PATH=%q\nexport DOCKER_HOST=%s\n\n%s\n",
cfg.machineDir, dockerHost, usageHint) cfg.machineDir, dockerHost, usageHint)
@ -98,6 +104,12 @@ func cmdEnv(c *cli.Context) {
func generateUsageHint(machineName string, userShell string) string { func generateUsageHint(machineName string, userShell string) string {
cmd := "" cmd := ""
switch userShell { switch userShell {
case "powershell":
if machineName != "" {
cmd = fmt.Sprintf("Param(docker-machine env %s)", machineName)
} else {
cmd = "Param(docker-machine env)"
}
case "fish": case "fish":
if machineName != "" { if machineName != "" {
cmd = fmt.Sprintf("eval (docker-machine env %s)", machineName) cmd = fmt.Sprintf("eval (docker-machine env %s)", machineName)

View File

@ -12,6 +12,7 @@ import (
"io" "io"
"os" "os"
"runtime" "runtime"
"syscall"
gossh "golang.org/x/crypto/ssh" gossh "golang.org/x/crypto/ssh"
) )
@ -82,7 +83,9 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
// windows does not support chmod // windows does not support chmod
switch runtime.GOOS { switch runtime.GOOS {
case "darwin", "linux": case "windows":
syscall.Chmod(f.Name(), 0600)
default:
if err := f.Chmod(0600); err != nil { if err := f.Chmod(0600); err != nil {
return err return err
} }