mirror of https://github.com/docker/docs.git
Default to cmd shell on windows
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
parent
c07067c7e4
commit
c279d0aba2
|
@ -248,16 +248,14 @@ func (g *EnvUsageHintGenerator) GenerateUsageHint(userShell string, args []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectShell() (string, error) {
|
func detectShell() (string, error) {
|
||||||
// attempt to get the SHELL env var
|
shell := os.Getenv("SHELL")
|
||||||
shell := filepath.Base(os.Getenv("SHELL"))
|
|
||||||
|
|
||||||
log.Debugf("shell: %s", shell)
|
|
||||||
if shell == "" {
|
if shell == "" {
|
||||||
// check for windows env and not bash (i.e. msysgit, etc)
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
log.Info("On Windows, please specify either 'cmd' or 'powershell' with the --shell flag.\n\n")
|
fmt.Printf("You can further specify your shell with either 'cmd' or 'powershell' with the --shell flag.\n\n")
|
||||||
|
return "cmd", nil // this could be either powershell or cmd, defaulting to cmd
|
||||||
}
|
}
|
||||||
|
fmt.Printf("The default lines below are for a sh/bash shell, you can specify the shell you're using, with the --shell flag.\n\n")
|
||||||
return "", ErrUnknownShell
|
return "", ErrUnknownShell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,5 +263,5 @@ func detectShell() (string, error) {
|
||||||
return "fish", nil
|
return "fish", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return shell, nil
|
return filepath.Base(shell), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/machine/commands/commandstest"
|
"github.com/docker/machine/commands/commandstest"
|
||||||
"github.com/docker/machine/commands/mcndirs"
|
"github.com/docker/machine/commands/mcndirs"
|
||||||
"github.com/docker/machine/drivers/fakedriver"
|
"github.com/docker/machine/drivers/fakedriver"
|
||||||
|
@ -549,20 +551,32 @@ func TestShellCfgUnset(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDetectBash(t *testing.T) {
|
func TestDetectBash(t *testing.T) {
|
||||||
original_shell := os.Getenv("SHELL")
|
originalShell := os.Getenv("SHELL")
|
||||||
os.Setenv("SHELL", "/bin/bash")
|
os.Setenv("SHELL", "/bin/bash")
|
||||||
defer os.Setenv("SHELL", original_shell)
|
defer os.Setenv("SHELL", originalShell)
|
||||||
shell, _ := detectShell()
|
shell, err := detectShell()
|
||||||
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "bash", shell)
|
assert.Equal(t, "bash", shell)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDetectFish(t *testing.T) {
|
func TestDetectFish(t *testing.T) {
|
||||||
original_shell := os.Getenv("SHELL")
|
originalShell := os.Getenv("SHELL")
|
||||||
os.Setenv("SHELL", "/bin/bash")
|
os.Setenv("SHELL", "/bin/bash")
|
||||||
defer os.Setenv("SHELL", original_shell)
|
defer os.Setenv("SHELL", originalShell)
|
||||||
original_fishdir := os.Getenv("__fish_bin_dir")
|
originalFishdir := os.Getenv("__fish_bin_dir")
|
||||||
os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin")
|
os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin")
|
||||||
defer os.Setenv("__fish_bin_dir", original_fishdir)
|
defer os.Setenv("__fish_bin_dir", originalFishdir)
|
||||||
shell, _ := detectShell()
|
shell, err := detectShell()
|
||||||
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "fish", shell)
|
assert.Equal(t, "fish", shell)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnknowShell(t *testing.T) {
|
||||||
|
originalShell := os.Getenv("SHELL")
|
||||||
|
os.Setenv("SHELL", "")
|
||||||
|
defer os.Setenv("SHELL", originalShell)
|
||||||
|
shell, err := detectShell()
|
||||||
|
fmt.Println(shell)
|
||||||
|
assert.Equal(t, err, ErrUnknownShell)
|
||||||
|
assert.Equal(t, "", shell)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDetect(t *testing.T) {
|
||||||
|
originalShell := os.Getenv("SHELL")
|
||||||
|
os.Setenv("SHELL", "")
|
||||||
|
defer os.Setenv("SHELL", originalShell)
|
||||||
|
shell, err := detectShell()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, "cmd", shell)
|
||||||
|
}
|
Loading…
Reference in New Issue