mirror of https://github.com/docker/docs.git
				
				
				
			Merge pull request #2734 from dgageot/shell-detect-package
Extract shell detection to its own package
This commit is contained in:
		
						commit
						d771d65dc4
					
				|  | @ -19,7 +19,6 @@ import ( | |||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	ErrUnknownShell       = errors.New("Error: Unknown shell") | ||||
| 	ErrNoMachineSpecified = errors.New("Error: Expected to get one or more machine names as arguments") | ||||
| 	ErrExpectedOneMachine = errors.New("Error: Expected one machine name as an argument") | ||||
| 	ErrTooManyArguments   = errors.New("Error: Too many arguments given") | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ import ( | |||
| 	"text/template" | ||||
| 
 | ||||
| 	"github.com/docker/machine/commands/mcndirs" | ||||
| 	"github.com/docker/machine/commands/shell" | ||||
| 	"github.com/docker/machine/libmachine" | ||||
| 	"github.com/docker/machine/libmachine/check" | ||||
| 	"github.com/docker/machine/libmachine/log" | ||||
|  | @ -200,7 +201,7 @@ func getShell(userShell string) (string, error) { | |||
| 	if userShell != "" { | ||||
| 		return userShell, nil | ||||
| 	} | ||||
| 	return detectShell() | ||||
| 	return shell.Detect() | ||||
| } | ||||
| 
 | ||||
| func findNoProxyFromEnv() (string, string) { | ||||
|  |  | |||
|  | @ -1,14 +1,20 @@ | |||
| // +build !windows
 | ||||
| 
 | ||||
| package commands | ||||
| package shell | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| ) | ||||
| 
 | ||||
| func detectShell() (string, error) { | ||||
| var ( | ||||
| 	ErrUnknownShell = errors.New("Error: Unknown shell") | ||||
| ) | ||||
| 
 | ||||
| // Detect detects user's current shell.
 | ||||
| func Detect() (string, error) { | ||||
| 	shell := os.Getenv("SHELL") | ||||
| 
 | ||||
| 	if shell == "" { | ||||
|  | @ -1,4 +1,4 @@ | |||
| package commands | ||||
| package shell | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
|  | @ -11,7 +11,7 @@ func TestDetectBash(t *testing.T) { | |||
| 	originalShell := os.Getenv("SHELL") | ||||
| 	os.Setenv("SHELL", "/bin/bash") | ||||
| 	defer os.Setenv("SHELL", originalShell) | ||||
| 	shell, err := detectShell() | ||||
| 	shell, err := Detect() | ||||
| 	assert.Nil(t, err) | ||||
| 	assert.Equal(t, "bash", shell) | ||||
| } | ||||
|  | @ -23,7 +23,7 @@ func TestDetectFish(t *testing.T) { | |||
| 	originalFishdir := os.Getenv("__fish_bin_dir") | ||||
| 	os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin") | ||||
| 	defer os.Setenv("__fish_bin_dir", originalFishdir) | ||||
| 	shell, err := detectShell() | ||||
| 	shell, err := Detect() | ||||
| 	assert.Nil(t, err) | ||||
| 	assert.Equal(t, "fish", shell) | ||||
| } | ||||
|  | @ -1,6 +1,6 @@ | |||
| // +build !windows
 | ||||
| 
 | ||||
| package commands | ||||
| package shell | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | @ -14,7 +14,7 @@ func TestUnknowShell(t *testing.T) { | |||
| 	originalShell := os.Getenv("SHELL") | ||||
| 	os.Setenv("SHELL", "") | ||||
| 	defer os.Setenv("SHELL", originalShell) | ||||
| 	shell, err := detectShell() | ||||
| 	shell, err := Detect() | ||||
| 	fmt.Println(shell) | ||||
| 	assert.Equal(t, err, ErrUnknownShell) | ||||
| 	assert.Equal(t, "", shell) | ||||
|  | @ -1,4 +1,4 @@ | |||
| package commands | ||||
| package shell | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | @ -50,7 +50,7 @@ func startedBy() (exefile string, err error) { | |||
| 	return name, nil | ||||
| } | ||||
| 
 | ||||
| func detectShell() (string, error) { | ||||
| func Detect() (string, error) { | ||||
| 	shell := os.Getenv("SHELL") | ||||
| 
 | ||||
| 	if shell == "" { | ||||
|  | @ -1,4 +1,4 @@ | |||
| package commands | ||||
| package shell | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
|  | @ -11,7 +11,7 @@ func TestDetect(t *testing.T) { | |||
| 	originalShell := os.Getenv("SHELL") | ||||
| 	os.Setenv("SHELL", "") | ||||
| 	defer os.Setenv("SHELL", originalShell) | ||||
| 	shell, err := detectShell() | ||||
| 	shell, err := Detect() | ||||
| 	assert.Nil(t, err) | ||||
| 	assert.Equal(t, "cmd", shell) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue