X Tutup
Skip to content

Commit d771d65

Browse files
committed
Merge pull request docker-archive-public#2734 from dgageot/shell-detect-package
Extract shell detection to its own package
2 parents 61fed5c + 5ff7ab9 commit d771d65

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

commands/commands.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
)
2020

2121
var (
22-
ErrUnknownShell = errors.New("Error: Unknown shell")
2322
ErrNoMachineSpecified = errors.New("Error: Expected to get one or more machine names as arguments")
2423
ErrExpectedOneMachine = errors.New("Error: Expected one machine name as an argument")
2524
ErrTooManyArguments = errors.New("Error: Too many arguments given")

commands/env.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"text/template"
1010

1111
"github.com/docker/machine/commands/mcndirs"
12+
"github.com/docker/machine/commands/shell"
1213
"github.com/docker/machine/libmachine"
1314
"github.com/docker/machine/libmachine/check"
1415
"github.com/docker/machine/libmachine/log"
@@ -200,7 +201,7 @@ func getShell(userShell string) (string, error) {
200201
if userShell != "" {
201202
return userShell, nil
202203
}
203-
return detectShell()
204+
return shell.Detect()
204205
}
205206

206207
func findNoProxyFromEnv() (string, string) {
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// +build !windows
22

3-
package commands
3+
package shell
44

55
import (
6+
"errors"
67
"fmt"
78
"os"
89
"path/filepath"
910
)
1011

11-
func detectShell() (string, error) {
12+
var (
13+
ErrUnknownShell = errors.New("Error: Unknown shell")
14+
)
15+
16+
// Detect detects user's current shell.
17+
func Detect() (string, error) {
1218
shell := os.Getenv("SHELL")
1319

1420
if shell == "" {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package commands
1+
package shell
22

33
import (
44
"os"
@@ -11,7 +11,7 @@ func TestDetectBash(t *testing.T) {
1111
originalShell := os.Getenv("SHELL")
1212
os.Setenv("SHELL", "/bin/bash")
1313
defer os.Setenv("SHELL", originalShell)
14-
shell, err := detectShell()
14+
shell, err := Detect()
1515
assert.Nil(t, err)
1616
assert.Equal(t, "bash", shell)
1717
}
@@ -23,7 +23,7 @@ func TestDetectFish(t *testing.T) {
2323
originalFishdir := os.Getenv("__fish_bin_dir")
2424
os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin")
2525
defer os.Setenv("__fish_bin_dir", originalFishdir)
26-
shell, err := detectShell()
26+
shell, err := Detect()
2727
assert.Nil(t, err)
2828
assert.Equal(t, "fish", shell)
2929
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build !windows
22

3-
package commands
3+
package shell
44

55
import (
66
"fmt"
@@ -14,7 +14,7 @@ func TestUnknowShell(t *testing.T) {
1414
originalShell := os.Getenv("SHELL")
1515
os.Setenv("SHELL", "")
1616
defer os.Setenv("SHELL", originalShell)
17-
shell, err := detectShell()
17+
shell, err := Detect()
1818
fmt.Println(shell)
1919
assert.Equal(t, err, ErrUnknownShell)
2020
assert.Equal(t, "", shell)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package commands
1+
package shell
22

33
import (
44
"fmt"
@@ -50,7 +50,7 @@ func startedBy() (exefile string, err error) {
5050
return name, nil
5151
}
5252

53-
func detectShell() (string, error) {
53+
func Detect() (string, error) {
5454
shell := os.Getenv("SHELL")
5555

5656
if shell == "" {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package commands
1+
package shell
22

33
import (
44
"os"
@@ -11,7 +11,7 @@ func TestDetect(t *testing.T) {
1111
originalShell := os.Getenv("SHELL")
1212
os.Setenv("SHELL", "")
1313
defer os.Setenv("SHELL", originalShell)
14-
shell, err := detectShell()
14+
shell, err := Detect()
1515
assert.Nil(t, err)
1616
assert.Equal(t, "cmd", shell)
1717
}

0 commit comments

Comments
 (0)
X Tutup