This repository has been archived by the owner. It is now read-only.

Fix shellinit output for cmd.exe/powershell #356

Merged
merged 1 commit into from Mar 26, 2015

Conversation

Projects
None yet
3 participants
@ahmetb
Contributor

ahmetb commented Mar 25, 2015

Also fixes the issue with Windows paths with backslashes in the bash
export statements.

When shellinit/up executed on windows, prints instructions on how to set
environment variables correctly for Windows Command Prompt (cmd.exe) and
PowerShell. (only the powershell set path statements are printed to
stdout; the rest goes to stderr).

We couldn't find a way to figure out if we're running on CMD or PowerShell, that's
why printing instructions for both.

Visualized:

Changes in MSYS window (used with "Boot2Docker Start" shortcut link), added single quotes around path.

CMD.exe output for for up (used to print "Docker client does not run on Windows for now"):

Powershell output for up (same as cmd.exe):

Powershell boot2docker shellinit | Invoke-Expression (notice that the PS commands are missing as they were on stdout and got piped to Invoke-Expression):

Signed-off-by: Ahmet Alp Balkan ahmetalpbalkan@gmail.com
cc: @tianon @johngossman

@ahmetb ahmetb referenced this pull request Mar 25, 2015

Closed

Proposal: Shipping Docker CLI for Windows #80

7 of 9 tasks complete
@tianon

This comment has been minimized.

Contributor

tianon commented Mar 25, 2015

A tiny bit hacky, but not unreasonably so. 👍

LGTM

cc @Moghedrin @gmlewis

cmds.go Outdated
fmt.Fprintln(os.Stderr, "")
// Print powershell instructions to stderr
fmt.Fprintln(os.Stderr, "If you are running inside PowerShell, copy or paste the following commands")
fmt.Fprintln(os.Stderr, "to your shell or run \"boot2docker shellinit | Invoke-Expression\" to set the")

This comment has been minimized.

@gmlewis

gmlewis Mar 25, 2015

Contributor

nit: Could be:

fmt.Fprintln(os.Stderr, `to your shell or run "boot2docker shellinit | Invoke-Expression" to set the`)
if value == "" {
fmt.Printf(" Remove-Item Env:\\%s\n", name)
} else {
fmt.Printf(" $Env:%s = \"%s\"\n", name, value)

This comment has been minimized.

@gmlewis

gmlewis Mar 25, 2015

Contributor

nit: could be: (also, there are a number of other places that could use Println instead of Printf... but not a big deal.)

fmt.Println(`    $Env:%s = "%s"`, name, value)

This comment has been minimized.

@ahmetb

ahmetb Mar 25, 2015

Contributor

@gmlewis this particular one is easy to fix. I'll just fix. Problem was mostly above where I can't have \n inside backticks with fmt.Fprintf. thanks.

This comment has been minimized.

@tianon

tianon Mar 25, 2015

Contributor

fmt.Println doesn't take a format string, does it?

This comment has been minimized.

@ahmetb

ahmetb Mar 25, 2015

Contributor

@gmlewis oh wait I can't fix this too, if I use Println I can't format %s 😄

This comment has been minimized.

@tianon

tianon Mar 25, 2015

Contributor

https://golang.org/pkg/fmt/#Println

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

This comment has been minimized.

@ahmetb

ahmetb Mar 25, 2015

Contributor

@tianon

    fmt.Println("    $Env:"+name, "=", `"`+value+`"`)

this looks ugly.

This comment has been minimized.

@tianon

tianon via email Mar 25, 2015

Contributor

This comment has been minimized.

@gmlewis

gmlewis Mar 25, 2015

Contributor

http://godoc.org/fmt#Println supports formatting. What I wrote should work, and IMHO looks best.

This comment has been minimized.

@ahmetb

This comment has been minimized.

@gmlewis

gmlewis Mar 26, 2015

Contributor

Wow, sorry. My bad.

Fix shellinit output for cmd.exe/powershell
Also fixes the issue with Windows paths with backslashes in the bash
`export` statements.

When shellinit/up executed on windows, prints instructions on how to set
environment variables correctly for Windows Command Prompt (cmd.exe) and
PowerShell. (only the powershell set path statements are printed to
stdout; the rest goes to stderr).

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
@gmlewis

This comment has been minimized.

Contributor

gmlewis commented Mar 25, 2015

A couple minor nits, otherwise LGTM.

tianon added a commit that referenced this pull request Mar 26, 2015

Merge pull request #356 from ahmetalpbalkan/shellinit-fix
Fix shellinit output for cmd.exe/powershell

@tianon tianon merged commit 63bf6b5 into boot2docker:master Mar 26, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@ahmetb ahmetb deleted the ahmetb:shellinit-fix branch Apr 14, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.