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
86f1d74a
Commit
86f1d74a
authored
Aug 31, 2017
by
tcharding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change error variable identifiers to ErrFoo
parent
a3627bda
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
17 deletions
+22
-17
plugins.go
pkg/kubectl/plugins/plugins.go
+15
-10
plugins_test.go
pkg/kubectl/plugins/plugins_test.go
+7
-7
No files found.
pkg/kubectl/plugins/plugins.go
View file @
86f1d74a
...
...
@@ -23,11 +23,16 @@ import (
)
var
(
IncompletePluginError
=
fmt
.
Errorf
(
"incomplete plugin descriptor: name, shortDesc and command fields are required"
)
InvalidPluginNameError
=
fmt
.
Errorf
(
"plugin name can't contain spaces"
)
IncompleteFlagError
=
fmt
.
Errorf
(
"incomplete flag descriptor: name and desc fields are required"
)
InvalidFlagNameError
=
fmt
.
Errorf
(
"flag name can't contain spaces"
)
InvalidFlagShorthandError
=
fmt
.
Errorf
(
"flag shorthand must be only one letter"
)
// ErrIncompletePlugin indicates plugin is incomplete.
ErrIncompletePlugin
=
fmt
.
Errorf
(
"incomplete plugin descriptor: name, shortDesc and command fields are required"
)
// ErrInvalidPluginName indicates plugin name is invalid.
ErrInvalidPluginName
=
fmt
.
Errorf
(
"plugin name can't contain spaces"
)
// ErrIncompleteFlag indicates flag is incomplete.
ErrIncompleteFlag
=
fmt
.
Errorf
(
"incomplete flag descriptor: name and desc fields are required"
)
// ErrInvalidFlagName indicates flag name is invalid.
ErrInvalidFlagName
=
fmt
.
Errorf
(
"flag name can't contain spaces"
)
// ErrInvalidFlagShorthand indicates flag shorthand is invalid.
ErrInvalidFlagShorthand
=
fmt
.
Errorf
(
"flag shorthand must be only one letter"
)
)
// Plugin is the representation of a CLI extension (plugin).
...
...
@@ -58,10 +63,10 @@ type Source struct {
// Validate validates plugin data.
func
(
p
Plugin
)
Validate
()
error
{
if
len
(
p
.
Name
)
==
0
||
len
(
p
.
ShortDesc
)
==
0
||
(
len
(
p
.
Command
)
==
0
&&
len
(
p
.
Tree
)
==
0
)
{
return
IncompletePluginError
return
ErrIncompletePlugin
}
if
strings
.
Index
(
p
.
Name
,
" "
)
>
-
1
{
return
InvalidPluginNameError
return
ErrInvalidPluginName
}
for
_
,
flag
:=
range
p
.
Flags
{
if
err
:=
flag
.
Validate
();
err
!=
nil
{
...
...
@@ -95,10 +100,10 @@ type Flag struct {
// Validate validates flag data.
func
(
f
Flag
)
Validate
()
error
{
if
len
(
f
.
Name
)
==
0
||
len
(
f
.
Desc
)
==
0
{
return
IncompleteFlagError
return
ErrIncompleteFlag
}
if
strings
.
Index
(
f
.
Name
,
" "
)
>
-
1
{
return
InvalidFlagNameError
return
ErrInvalidFlagName
}
return
f
.
ValidateShorthand
()
}
...
...
@@ -109,7 +114,7 @@ func (f Flag) ValidateShorthand() error {
if
length
==
0
||
(
length
==
1
&&
unicode
.
IsLetter
(
rune
(
f
.
Shorthand
[
0
])))
{
return
nil
}
return
InvalidFlagShorthandError
return
ErrInvalidFlagShorthand
}
// Shorthanded returns true if flag shorthand data is valid.
...
...
pkg/kubectl/plugins/plugins_test.go
View file @
86f1d74a
...
...
@@ -39,11 +39,11 @@ func TestPlugin(t *testing.T) {
ShortDesc
:
"The test"
,
},
},
expectedErr
:
IncompletePluginError
,
expectedErr
:
ErrIncompletePlugin
,
},
{
plugin
:
&
Plugin
{},
expectedErr
:
IncompletePluginError
,
expectedErr
:
ErrIncompletePlugin
,
},
{
plugin
:
&
Plugin
{
...
...
@@ -53,7 +53,7 @@ func TestPlugin(t *testing.T) {
Command
:
"echo 1"
,
},
},
expectedErr
:
InvalidPluginNameError
,
expectedErr
:
ErrInvalidPluginName
,
},
{
plugin
:
&
Plugin
{
...
...
@@ -68,7 +68,7 @@ func TestPlugin(t *testing.T) {
},
},
},
expectedErr
:
IncompleteFlagError
,
expectedErr
:
ErrIncompleteFlag
,
},
{
plugin
:
&
Plugin
{
...
...
@@ -84,7 +84,7 @@ func TestPlugin(t *testing.T) {
},
},
},
expectedErr
:
InvalidFlagNameError
,
expectedErr
:
ErrInvalidFlagName
,
},
{
plugin
:
&
Plugin
{
...
...
@@ -101,7 +101,7 @@ func TestPlugin(t *testing.T) {
},
},
},
expectedErr
:
InvalidFlagShorthandError
,
expectedErr
:
ErrInvalidFlagShorthand
,
},
{
plugin
:
&
Plugin
{
...
...
@@ -118,7 +118,7 @@ func TestPlugin(t *testing.T) {
},
},
},
expectedErr
:
InvalidFlagShorthandError
,
expectedErr
:
ErrInvalidFlagShorthand
,
},
{
plugin
:
&
Plugin
{
...
...
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