Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Chu Peng 楚鹏
minikube
提交
2033f8dc
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,发现更多精彩内容 >>
提交
2033f8dc
编写于
2月 07, 2019
作者:
T
Thomas Stromberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Further tuning, especially of env override
上级
d1b0d047
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
40 deletion
+84
-40
Gopkg.lock
Gopkg.lock
+21
-1
Gopkg.toml
Gopkg.toml
+3
-0
pkg/minikube/console/console.go
pkg/minikube/console/console.go
+34
-23
pkg/minikube/console/console_test.go
pkg/minikube/console/console_test.go
+20
-12
pkg/minikube/console/style.go
pkg/minikube/console/style.go
+6
-4
未找到文件。
Gopkg.lock
浏览文件 @
2033f8dc
...
...
@@ -347,6 +347,14 @@
pruneopts = "NUT"
revision = "61b492c03cf472e0c6419be5899b8e0dc28b1b88"
[[projects]]
digest = "1:bffa444ca07c69c599ae5876bc18b25bfd5fa85b297ca10a25594d284a7e9c5d"
name = "github.com/mattn/go-isatty"
packages = ["."]
pruneopts = "NUT"
revision = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c"
version = "v0.0.4"
[[projects]]
digest = "1:f2d263faf8641cd0a31bba2d034eb2f9ab9f3c3348b06ac9ad54b9a4ea692dee"
name = "github.com/mattn/go-runewidth"
...
...
@@ -647,12 +655,20 @@
revision = "95c6576299259db960f6c5b9b69ea52422860fce"
[[projects]]
digest = "1:
97337ef8cb438f9e3a99ea91a300e916ed9a96fbf3ad50f9a020d30ea9f8692f
"
digest = "1:
5b12278b98e82aecd7d0b84e0b5fba67f37aba8fde89fa86d51e30556d381a4c
"
name = "golang.org/x/text"
packages = [
"internal",
"internal/catmsg",
"internal/gen",
"internal/number",
"internal/stringset",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"message",
"message/catalog",
"secure/bidirule",
"transform",
"unicode/bidi",
...
...
@@ -943,6 +959,8 @@
"github.com/johanneswuerbach/nfsexports",
"github.com/libvirt/libvirt-go",
"github.com/machine-drivers/docker-machine-driver-vmware/pkg/drivers/vmware/config",
"github.com/mattn/go-isatty",
"github.com/mitchellh/go-ps",
"github.com/moby/hyperkit/go",
"github.com/olekukonko/tablewriter",
"github.com/pborman/uuid",
...
...
@@ -963,6 +981,8 @@
"golang.org/x/sync/errgroup",
"golang.org/x/sync/syncmap",
"golang.org/x/sys/windows/registry",
"golang.org/x/text/language",
"golang.org/x/text/message",
"k8s.io/api/apps/v1",
"k8s.io/api/core/v1",
"k8s.io/api/rbac/v1beta1",
...
...
Gopkg.toml
浏览文件 @
2033f8dc
...
...
@@ -110,3 +110,6 @@
go-tests
=
true
non-go
=
true
unused-packages
=
true
[[constraint]]
name
=
"golang.org/x/text"
pkg/minikube/console/console.go
浏览文件 @
2033f8dc
...
...
@@ -23,6 +23,8 @@ import (
// console.SetErrFile(os.Stderr)
// console.Fatal("Oh no, everything failed.")
// NOTE: If you do not want colorized output, set MINIKUBE_IN_COLOR=0 in your environment.
var
(
// outFile is where Out* functions send output to. Set using SetOutFile()
outFile
fdWriter
...
...
@@ -32,10 +34,10 @@ var (
preferredLanguage
=
language
.
AmericanEnglish
// our default language
defaultLanguage
=
language
.
AmericanEnglish
// ignoreTTYCheck ignores the result of the TTY check (for testing!)
ignoreTTYCheck
=
false
// useColor is whether or not color output should be used, updated by Set*Writer.
useColor
=
false
// OverrideEnv is the environment variable used to override color/emoji usage
OverrideEnv
=
"MINIKUBE_IN_COLOR"
)
// fdWriter is the subset of file.File that implements io.Writer and Fd()
...
...
@@ -61,7 +63,10 @@ func OutStyle(style, format string, a ...interface{}) error {
func
Out
(
format
string
,
a
...
interface
{})
error
{
p
:=
message
.
NewPrinter
(
preferredLanguage
)
if
outFile
==
nil
{
return
fmt
.
Errorf
(
"No output file has been set"
)
if
_
,
err
:=
p
.
Fprintf
(
os
.
Stdout
,
"(stdout unset)"
+
format
,
a
...
);
err
!=
nil
{
return
err
}
return
fmt
.
Errorf
(
"no output file has been set"
)
}
_
,
err
:=
p
.
Fprintf
(
outFile
,
format
,
a
...
)
return
err
...
...
@@ -76,9 +81,10 @@ func OutLn(format string, a ...interface{}) error {
func
ErrStyle
(
style
,
format
string
,
a
...
interface
{})
error
{
format
,
err
:=
applyStyle
(
style
,
useColor
,
fmt
.
Sprintf
(
format
,
a
...
))
if
err
!=
nil
{
glog
.
Errorf
(
"applyStyle(%s): %v"
,
style
,
err
)
// Try anyways.
if
err
:=
Err
(
format
);
err
!=
nil
{
glog
.
Errorf
(
"Err
failed: %v"
,
err
)
glog
.
Errorf
(
"Err
(%s) failed: %v"
,
format
,
err
)
}
return
err
}
...
...
@@ -89,7 +95,10 @@ func ErrStyle(style, format string, a ...interface{}) error {
func
Err
(
format
string
,
a
...
interface
{})
error
{
p
:=
message
.
NewPrinter
(
preferredLanguage
)
if
errFile
==
nil
{
return
fmt
.
Errorf
(
"No error output file has been set"
)
if
_
,
err
:=
p
.
Fprintf
(
os
.
Stderr
,
"(stderr unset)"
+
format
,
a
...
);
err
!=
nil
{
return
err
}
return
fmt
.
Errorf
(
"no error file has been set"
)
}
_
,
err
:=
p
.
Fprintf
(
errFile
,
format
,
a
...
)
return
err
...
...
@@ -120,16 +129,16 @@ func Failure(format string, a ...interface{}) error {
return
ErrStyle
(
"failure"
,
format
,
a
...
)
}
// SetLanguageTag configures which language future messages should use.
func
SetLanguageTag
(
l
language
.
Tag
)
{
// Set
Preferred
LanguageTag configures which language future messages should use.
func
Set
Preferred
LanguageTag
(
l
language
.
Tag
)
{
glog
.
Infof
(
"Setting Language to %s ..."
,
l
)
preferredLanguage
=
l
}
// SetLanguage configures which language future messages should use, based on a LANG string.
func
SetLanguage
(
s
string
)
error
{
// Set
Preferred
Language configures which language future messages should use, based on a LANG string.
func
Set
Preferred
Language
(
s
string
)
error
{
if
s
==
""
||
s
==
"C"
{
SetLanguageTag
(
defaultLanguage
)
Set
Preferred
LanguageTag
(
defaultLanguage
)
return
nil
}
// Ignore encoding preferences: we always output utf8. Handles "de_DE.utf8"
...
...
@@ -138,40 +147,42 @@ func SetLanguage(s string) error {
if
err
!=
nil
{
return
err
}
SetLanguageTag
(
l
)
Set
Preferred
LanguageTag
(
l
)
return
nil
}
// SetOutFile configures which writer standard output goes to.
func
SetOutFile
(
w
fdWriter
)
{
glog
.
Infof
(
"Setting OutFile to
%v (fd=%d) ..."
,
w
,
w
.
Fd
())
glog
.
Infof
(
"Setting OutFile to
fd %d ..."
,
w
.
Fd
())
outFile
=
w
useColor
=
wantsColor
(
w
.
Fd
())
}
// SetErrFile configures which writer error output goes to.
func
SetErrFile
(
w
fdWriter
)
{
glog
.
Infof
(
"Setting ErrFile to
%v (fd=%d)..."
,
w
,
w
.
Fd
())
glog
.
Infof
(
"Setting ErrFile to
fd %d..."
,
w
.
Fd
())
errFile
=
w
useColor
=
wantsColor
(
w
.
Fd
())
}
// wantsColor determines if the user might want colorized output.
func
wantsColor
(
fd
uintptr
)
bool
{
// As in: term-256color
if
!
strings
.
Contains
(
os
.
Getenv
(
"TERM"
),
"color"
)
{
glog
.
Infof
(
"TERM does not appear to support color"
)
glog
.
Infof
(
"%s=%q
\n
"
,
OverrideEnv
,
os
.
Getenv
(
OverrideEnv
))
switch
os
.
Getenv
(
OverrideEnv
)
{
case
"0"
:
return
false
case
"1"
:
return
true
}
// Allow boring people to continue to be boring people.
if
os
.
Getenv
(
"MINIKUBE_IS_BORING"
)
==
"1"
{
glog
.
Infof
(
"minikube is boring."
)
term
:=
os
.
Getenv
(
"TERM"
)
// As in: term-256color
if
!
strings
.
Contains
(
term
,
"color"
)
{
glog
.
Infof
(
"TERM=%s, which probably does not support color"
,
term
)
return
false
}
if
ignoreTTYCheck
{
return
true
}
isT
:=
isatty
.
IsTerminal
(
fd
)
glog
.
Infof
(
"
IsTerminal(%d) = %v
"
,
fd
,
isT
)
glog
.
Infof
(
"
isatty.IsTerminal(%d) = %v
\n
"
,
fd
,
isT
)
return
isT
}
pkg/minikube/console/console_test.go
浏览文件 @
2033f8dc
...
...
@@ -2,6 +2,7 @@ package console
import
(
"bytes"
"os"
"testing"
"golang.org/x/text/language"
...
...
@@ -14,8 +15,6 @@ type fakeFile struct {
}
func
newFakeFile
()
*
fakeFile
{
// So that we don't have to fully emulate being a terminal
ignoreTTYCheck
=
true
return
&
fakeFile
{}
}
...
...
@@ -31,6 +30,7 @@ func (f *fakeFile) String() string {
}
func
TestOutStyle
(
t
*
testing
.
T
)
{
os
.
Setenv
(
OverrideEnv
,
""
)
f
:=
newFakeFile
()
SetOutFile
(
f
)
if
err
:=
OutStyle
(
"happy"
,
"This is a happy message."
);
err
!=
nil
{
...
...
@@ -45,23 +45,29 @@ func TestOutStyle(t *testing.T) {
}
func
TestOut
(
t
*
testing
.
T
)
{
os
.
Setenv
(
OverrideEnv
,
""
)
// An example translation just to assert that this code path is executed.
message
.
SetString
(
language
.
Arabic
,
"Installing Kubernetes version %s ..."
,
"... %s تثبيت Kubernetes الإصدار"
)
SetLanguageTag
(
language
.
Arabic
)
err
:=
message
.
SetString
(
language
.
Arabic
,
"Installing Kubernetes version %s ..."
,
"... %s تثبيت Kubernetes الإصدار"
)
if
err
!=
nil
{
t
.
Fatalf
(
"setstring: %v"
,
err
)
}
var
tests
=
[]
struct
{
format
string
lang
language
.
Tag
arg
string
want
string
}{
{
format
:
"xyz123"
,
want
:
"xyz123"
},
{
format
:
"Installing Kubernetes version %s ..."
,
arg
:
"v1.13"
,
want
:
"... v1.13 تثبيت Kubernetes الإصدار"
},
{
format
:
"Installing Kubernetes version %s ..."
,
lang
:
language
.
Arabic
,
arg
:
"v1.13"
,
want
:
"... v1.13 تثبيت Kubernetes الإصدار"
},
{
format
:
"Installing Kubernetes version %s ..."
,
lang
:
language
.
AmericanEnglish
,
arg
:
"v1.13"
,
want
:
"Installing Kubernetes version v1.13 ..."
},
}
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
format
,
func
(
t
*
testing
.
T
)
{
SetPreferredLanguageTag
(
tc
.
lang
)
f
:=
newFakeFile
()
SetOutFile
(
f
)
Err
(
"unrelated message"
)
Err
Ln
(
"unrelated message"
)
if
err
:=
Out
(
tc
.
format
,
tc
.
arg
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %q"
,
err
)
}
...
...
@@ -74,13 +80,14 @@ func TestOut(t *testing.T) {
}
func
TestErr
(
t
*
testing
.
T
)
{
os
.
Setenv
(
OverrideEnv
,
"0"
)
f
:=
newFakeFile
()
SetErrFile
(
f
)
if
err
:=
Err
(
"xyz123
\n
"
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %q"
,
err
)
}
Out
(
"unrelated message"
)
Out
Ln
(
"unrelated message"
)
got
:=
f
.
String
()
want
:=
"xyz123
\n
"
...
...
@@ -90,6 +97,7 @@ func TestErr(t *testing.T) {
}
func
TestErrStyle
(
t
*
testing
.
T
)
{
os
.
Setenv
(
OverrideEnv
,
"1"
)
f
:=
newFakeFile
()
SetErrFile
(
f
)
if
err
:=
ErrStyle
(
"fatal"
,
"It broke"
);
err
!=
nil
{
...
...
@@ -102,8 +110,8 @@ func TestErrStyle(t *testing.T) {
}
}
func
TestSetLanguage
(
t
*
testing
.
T
)
{
func
TestSet
Preferred
Language
(
t
*
testing
.
T
)
{
os
.
Setenv
(
OverrideEnv
,
"0"
)
var
tests
=
[]
struct
{
input
string
want
language
.
Tag
...
...
@@ -116,8 +124,8 @@ func TestSetLanguage(t *testing.T) {
for
_
,
tc
:=
range
tests
{
t
.
Run
(
tc
.
input
,
func
(
t
*
testing
.
T
)
{
// Set something so that we can assert change.
SetLanguageTag
(
language
.
Icelandic
)
if
err
:=
SetLanguage
(
tc
.
input
);
err
!=
nil
{
Set
Preferred
LanguageTag
(
language
.
Icelandic
)
if
err
:=
Set
Preferred
Language
(
tc
.
input
);
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %q"
,
err
)
}
...
...
@@ -125,7 +133,7 @@ func TestSetLanguage(t *testing.T) {
want
,
_
:=
tc
.
want
.
Base
()
got
,
_
:=
preferredLanguage
.
Base
()
if
got
!=
want
{
t
.
Errorf
(
"SetLanguage(%s) = %q, want %q"
,
tc
.
input
,
got
,
want
)
t
.
Errorf
(
"Set
Preferred
Language(%s) = %q, want %q"
,
tc
.
input
,
got
,
want
)
}
})
}
...
...
pkg/minikube/console/style.go
浏览文件 @
2033f8dc
...
...
@@ -62,9 +62,11 @@ func applyPrefix(prefix, format string) string {
// Apply styling to a format string
func
applyStyle
(
style
string
,
useColor
bool
,
format
string
,
a
...
interface
{})
(
string
,
error
)
{
p
:=
message
.
NewPrinter
(
preferredLanguage
)
out
:=
p
.
Sprintf
(
format
,
a
...
)
s
,
ok
:=
styles
[
style
]
if
!
s
.
OmitNewline
{
format
=
format
+
"
\n
"
out
+=
"
\n
"
}
// Similar to CSS styles, if no style matches, output an unformatted string.
...
...
@@ -73,9 +75,9 @@ func applyStyle(style string, useColor bool, format string, a ...interface{}) (s
}
prefix
:=
s
.
Prefix
if
useColor
&&
prefix
!=
""
{
if
!
useColor
&&
prefix
!=
""
{
prefix
=
"-"
}
format
=
applyPrefix
(
prefix
,
forma
t
)
return
p
.
Sprintf
(
format
,
a
...
)
,
nil
out
=
applyPrefix
(
prefix
,
ou
t
)
return
out
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录