Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
ae2ceee8
M
minikube
项目概览
Chu Peng 楚鹏
/
minikube
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
minikube
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ae2ceee8
编写于
5月 31, 2020
作者:
M
Marcin Niemira
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor cleanup
上级
168f67bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
36 deletion
+53
-36
pkg/minikube/shell/shell.go
pkg/minikube/shell/shell.go
+20
-21
pkg/minikube/shell/shell_test.go
pkg/minikube/shell/shell_test.go
+33
-15
未找到文件。
pkg/minikube/shell/shell.go
浏览文件 @
ae2ceee8
...
...
@@ -48,9 +48,9 @@ var shellConfigMap = map[string]shellData{
UnsetDelimiter
:
""
,
usageHint
:
func
(
s
...
interface
{})
string
{
return
fmt
.
Sprintf
(
`
# %s
# %s | source
`
,
s
...
)
# %s
# %s | source
`
,
s
...
)
},
},
"powershell"
:
shellData
{
...
...
@@ -62,8 +62,8 @@ var shellConfigMap = map[string]shellData{
""
,
func
(
s
...
interface
{})
string
{
return
fmt
.
Sprintf
(
`# %s
# & %s | Invoke-Expression
`
,
s
...
)
# & %s | Invoke-Expression
`
,
s
...
)
},
},
"cmd"
:
shellData
{
...
...
@@ -75,8 +75,8 @@ var shellConfigMap = map[string]shellData{
"="
,
func
(
s
...
interface
{})
string
{
return
fmt
.
Sprintf
(
`REM %s
REM @FOR /f "tokens=*" %%i IN ('%s') DO @%%i
`
,
s
...
)
REM @FOR /f "tokens=*" %%i IN ('%s') DO @%%i
`
,
s
...
)
},
},
"emacs"
:
shellData
{
...
...
@@ -88,8 +88,8 @@ var shellConfigMap = map[string]shellData{
"
\"
nil"
,
func
(
s
...
interface
{})
string
{
return
fmt
.
Sprintf
(
`;; %s
;; (with-temp-buffer (shell-command "%s" (current-buffer)) (eval-buffer))
`
,
s
...
)
;; (with-temp-buffer (shell-command "%s" (current-buffer)) (eval-buffer))
`
,
s
...
)
},
},
"bash"
:
shellData
{
...
...
@@ -101,9 +101,9 @@ var shellConfigMap = map[string]shellData{
""
,
func
(
s
...
interface
{})
string
{
return
fmt
.
Sprintf
(
`
# %s
# eval $(%s)
`
,
s
...
)
# %s
# eval $(%s)
`
,
s
...
)
},
},
"none"
:
shellData
{
...
...
@@ -114,7 +114,10 @@ var shellConfigMap = map[string]shellData{
"
\n
"
,
"="
,
func
(
s
...
interface
{})
string
{
return
""
return
fmt
.
Sprintf
(
`
# %s
# eval $(%s)
`
,
s
...
)
},
},
}
...
...
@@ -149,18 +152,14 @@ func generateUsageHint(sh, usgPlz, usgCmd string) string {
// CfgSet generates context variables for shell
func
CfgSet
(
ec
EnvConfig
,
plz
,
cmd
string
)
*
Config
{
shellKey
,
s
:=
ec
.
Shell
,
&
Config
{}
shellCfg
,
ok
:=
shellConfigMap
[
shellKey
]
shellCfg
,
ok
:=
shellConfigMap
[
ec
.
Shell
]
if
!
ok
{
shellCfg
=
defaultShell
}
s
.
Suffix
,
s
.
Prefix
,
s
.
Delimiter
=
shellCfg
.
Suffix
,
shellCfg
.
Prefix
,
shellCfg
.
Delimiter
if
shellKey
!=
"none"
{
s
.
UsageHint
=
generateUsageHint
(
ec
.
Shell
,
plz
,
cmd
)
}
s
:=
&
Config
{}
s
.
Suffix
,
s
.
Prefix
,
s
.
Delimiter
=
shellCfg
.
Suffix
,
shellCfg
.
Prefix
,
shellCfg
.
Delimiter
s
.
UsageHint
=
generateUsageHint
(
ec
.
Shell
,
plz
,
cmd
)
return
s
}
...
...
pkg/minikube/shell/shell_test.go
浏览文件 @
ae2ceee8
...
...
@@ -24,18 +24,30 @@ import (
func
TestGenerateUsageHint
(
t
*
testing
.
T
)
{
var
testCases
=
[]
struct
{
shellType
,
hintContains
string
shellType
,
expected
string
}{
{
""
,
"eval"
},
{
"powershell"
,
"Invoke-Expression"
},
{
"bash"
,
"eval"
},
{
""
,
`# foo
# eval $(bar)`
},
{
"powershell"
,
`# foo
# & bar | Invoke-Expression`
},
{
"bash"
,
`# foo
# eval $(bar)`
},
{
"powershell"
,
`# foo
# & bar | Invoke-Expression`
},
{
"emacs"
,
`;; foo
;; (with-temp-buffer (shell-command "bar" (current-buffer)) (eval-buffer))`
},
{
"fish"
,
`# foo
# bar | source`
},
{
"none"
,
`# foo
# eval $(bar)`
},
}
for
_
,
tc
:=
range
testCases
{
tc
:=
tc
t
.
Run
(
tc
.
shellType
,
func
(
t
*
testing
.
T
)
{
hint
:=
generateUsageHint
(
tc
.
shellType
,
"foo"
,
"bar"
)
if
!
strings
.
Contains
(
hint
,
tc
.
hintContains
)
{
t
.
Errorf
(
"Hint doesn't contain expected string. Expected to find '%v' in '%v'"
,
tc
.
hintContains
,
hint
)
got
:=
strings
.
TrimSpace
(
generateUsageHint
(
tc
.
shellType
,
"foo"
,
"bar"
))
expected
:=
strings
.
TrimSpace
(
tc
.
expected
)
if
got
!=
expected
{
t
.
Errorf
(
"Expected '%v' but got '%v'"
,
expected
,
got
)
}
})
}
...
...
@@ -74,13 +86,16 @@ func TestUnsetScript(t *testing.T) {
ec
EnvConfig
expected
string
}{
{[]
string
{
"baz"
},
EnvConfig
{
""
},
`unset baz`
},
{[]
string
{
"baz"
},
EnvConfig
{
"bash"
},
`unset baz`
},
{[]
string
{
"baz"
},
EnvConfig
{
"powershell"
},
`Remove-Item Env:\\baz`
},
{[]
string
{
"baz"
},
EnvConfig
{
"cmd"
},
`SET baz=`
},
{[]
string
{
"baz"
},
EnvConfig
{
"fish"
},
`set -e baz;`
},
{[]
string
{
"baz"
},
EnvConfig
{
"emacs"
},
`(setenv "baz" nil)`
},
{[]
string
{
"baz"
},
EnvConfig
{
"none"
},
`baz`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
""
},
`unset baz bar`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"bash"
},
`unset baz bar`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"powershell"
},
`Remove-Item Env:\\baz Env:\\bar`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"cmd"
},
`SET baz=
SET bar=`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"fish"
},
`set -e baz;
set -e bar;`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"emacs"
},
`(setenv "baz" nil)
(setenv "bar" nil)`
},
{[]
string
{
"baz"
,
"bar"
},
EnvConfig
{
"none"
},
`baz bar`
},
}
for
_
,
tc
:=
range
testCases
{
tc
:=
tc
...
...
@@ -102,7 +117,7 @@ func TestUnsetScript(t *testing.T) {
func
TestDetect
(
t
*
testing
.
T
)
{
if
s
,
err
:=
Detect
();
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: '%v' during shell detection
"
,
err
)
t
.
Fatalf
(
"unexpected error: '%v' during shell detection
. Returned shell: %s"
,
err
,
s
)
}
else
if
s
==
""
{
t
.
Fatalf
(
"Detected shell expected to be non empty string"
)
}
...
...
@@ -117,4 +132,7 @@ func TestSetScript(t *testing.T) {
if
w
.
String
()
!=
"foo"
{
t
.
Fatalf
(
"Expected foo writed by SetScript, but got '%v'"
,
w
.
String
())
}
if
ec
.
Shell
==
""
{
t
.
Fatalf
(
"Expected no empty shell"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录