Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3afa6954
Commit
3afa6954
authored
Sep 10, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13728 from mfojtik/intercept-exit
Auto commit by PR queue bot
parents
703130e8
fb14c8cd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
16 deletions
+25
-16
helpers.go
pkg/kubectl/cmd/util/helpers.go
+25
-16
No files found.
pkg/kubectl/cmd/util/helpers.go
View file @
3afa6954
...
...
@@ -62,13 +62,37 @@ func AddSourceToErr(verb string, source string, err error) error {
return
err
}
var
fatalErrHandler
=
fatal
// BehaviorOnFatal allows you to override the default behavior when a fatal
// error occurs, which is call os.Exit(1). You can pass 'panic' as a function
// here if you prefer the panic() over os.Exit(1).
func
BehaviorOnFatal
(
f
func
(
string
))
{
fatalErrHandler
=
f
}
// fatal prints the message and then exits. If V(2) or greater, glog.Fatal
// is invoked for extended information.
func
fatal
(
msg
string
)
{
// add newline if needed
if
!
strings
.
HasSuffix
(
msg
,
"
\n
"
)
{
msg
+=
"
\n
"
}
if
glog
.
V
(
2
)
{
glog
.
FatalDepth
(
2
,
msg
)
}
fmt
.
Fprint
(
os
.
Stderr
,
msg
)
os
.
Exit
(
1
)
}
// CheckErr prints a user friendly error to STDERR and exits with a non-zero
// exit code. Unrecognized errors will be printed with an "error: " prefix.
//
// This method is generic to the command in use and may be used by non-Kubectl
// commands.
func
CheckErr
(
err
error
)
{
checkErr
(
err
,
fatal
)
checkErr
(
err
,
fatal
ErrHandler
)
}
func
checkErr
(
err
error
,
handleErr
func
(
string
))
{
...
...
@@ -180,21 +204,6 @@ func messageForError(err error) string {
return
msg
}
// fatal prints the message and then exits. If V(2) or greater, glog.Fatal
// is invoked for extended information.
func
fatal
(
msg
string
)
{
// add newline if needed
if
!
strings
.
HasSuffix
(
msg
,
"
\n
"
)
{
msg
+=
"
\n
"
}
if
glog
.
V
(
2
)
{
glog
.
FatalDepth
(
2
,
msg
)
}
fmt
.
Fprint
(
os
.
Stderr
,
msg
)
os
.
Exit
(
1
)
}
func
UsageError
(
cmd
*
cobra
.
Command
,
format
string
,
args
...
interface
{})
error
{
msg
:=
fmt
.
Sprintf
(
format
,
args
...
)
return
fmt
.
Errorf
(
"%s
\n
see '%s -h' for help."
,
msg
,
cmd
.
CommandPath
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment