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
bc422f07
Commit
bc422f07
authored
Mar 09, 2016
by
harry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor bool_flag into sub pkg
parent
b6924a32
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
70 deletions
+90
-70
create_authinfo.go
pkg/kubectl/cmd/config/create_authinfo.go
+2
-1
create_cluster.go
pkg/kubectl/cmd/config/create_cluster.go
+3
-2
view.go
pkg/kubectl/cmd/config/view.go
+2
-2
bool_flag.go
pkg/util/bool_flag.go
+0
-65
tristate.go
pkg/util/flag/tristate.go
+83
-0
No files found.
pkg/kubectl/cmd/config/create_authinfo.go
View file @
bc422f07
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/flag"
)
)
type
createAuthInfoOptions
struct
{
type
createAuthInfoOptions
struct
{
...
@@ -40,7 +41,7 @@ type createAuthInfoOptions struct {
...
@@ -40,7 +41,7 @@ type createAuthInfoOptions struct {
token
util
.
StringFlag
token
util
.
StringFlag
username
util
.
StringFlag
username
util
.
StringFlag
password
util
.
StringFlag
password
util
.
StringFlag
embedCertData
util
.
BoolFlag
embedCertData
flag
.
Tristate
}
}
var
create_authinfo_long
=
fmt
.
Sprintf
(
`Sets a user entry in kubeconfig
var
create_authinfo_long
=
fmt
.
Sprintf
(
`Sets a user entry in kubeconfig
...
...
pkg/kubectl/cmd/config/create_cluster.go
View file @
bc422f07
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/flag"
)
)
type
createClusterOptions
struct
{
type
createClusterOptions
struct
{
...
@@ -35,9 +36,9 @@ type createClusterOptions struct {
...
@@ -35,9 +36,9 @@ type createClusterOptions struct {
name
string
name
string
server
util
.
StringFlag
server
util
.
StringFlag
apiVersion
util
.
StringFlag
apiVersion
util
.
StringFlag
insecureSkipTLSVerify
util
.
BoolFlag
insecureSkipTLSVerify
flag
.
Tristate
certificateAuthority
util
.
StringFlag
certificateAuthority
util
.
StringFlag
embedCAData
util
.
BoolFlag
embedCAData
flag
.
Tristate
}
}
const
(
const
(
...
...
pkg/kubectl/cmd/config/view.go
View file @
bc422f07
...
@@ -28,12 +28,12 @@ import (
...
@@ -28,12 +28,12 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util
/flag
"
)
)
type
ViewOptions
struct
{
type
ViewOptions
struct
{
ConfigAccess
ConfigAccess
ConfigAccess
ConfigAccess
Merge
util
.
BoolFlag
Merge
flag
.
Tristate
Flatten
bool
Flatten
bool
Minify
bool
Minify
bool
RawByteData
bool
RawByteData
bool
...
...
pkg/util/bool_flag.go
deleted
100644 → 0
View file @
b6924a32
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"fmt"
"strconv"
)
// BoolFlag is a boolean flag compatible with flags and pflags that keeps track of whether it had a value supplied or not.
// Getting this flag to act like a normal bool, where true/false are not required needs a little bit of extra code, example:
// f := cmd.Flags().VarPF(&BoolFlagVar, "flagname", "", "help about the flag")
// f.NoOptDefVal = "true"
type
BoolFlag
struct
{
// If Set has been invoked this value is true
provided
bool
// The exact value provided on the flag
value
bool
}
func
(
f
*
BoolFlag
)
Default
(
value
bool
)
{
f
.
value
=
value
}
func
(
f
BoolFlag
)
String
()
string
{
return
fmt
.
Sprintf
(
"%t"
,
f
.
value
)
}
func
(
f
BoolFlag
)
Value
()
bool
{
return
f
.
value
}
func
(
f
*
BoolFlag
)
Set
(
value
string
)
error
{
boolVal
,
err
:=
strconv
.
ParseBool
(
value
)
if
err
!=
nil
{
return
err
}
f
.
value
=
boolVal
f
.
provided
=
true
return
nil
}
func
(
f
BoolFlag
)
Provided
()
bool
{
return
f
.
provided
}
func
(
f
*
BoolFlag
)
Type
()
string
{
return
"bool"
}
pkg/util/flag/tristate.go
0 → 100644
View file @
bc422f07
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
flag
import
(
"fmt"
"strconv"
)
// Tristate is a flag compatible with flags and pflags that
// keeps track of whether it had a value supplied or not.
type
Tristate
int
const
(
Unset
Tristate
=
iota
// 0
True
False
)
func
(
f
*
Tristate
)
Default
(
value
bool
)
{
*
f
=
triFromBool
(
value
)
}
func
(
f
Tristate
)
String
()
string
{
b
:=
boolFromTri
(
f
)
return
fmt
.
Sprintf
(
"%t"
,
b
)
}
func
(
f
Tristate
)
Value
()
bool
{
b
:=
boolFromTri
(
f
)
return
b
}
func
(
f
*
Tristate
)
Set
(
value
string
)
error
{
boolVal
,
err
:=
strconv
.
ParseBool
(
value
)
if
err
!=
nil
{
return
err
}
*
f
=
triFromBool
(
boolVal
)
return
nil
}
func
(
f
Tristate
)
Provided
()
bool
{
if
f
!=
Unset
{
return
true
}
return
false
}
func
(
f
*
Tristate
)
Type
()
string
{
return
"tristate"
}
func
boolFromTri
(
t
Tristate
)
bool
{
if
t
==
True
{
return
true
}
else
{
return
false
}
}
func
triFromBool
(
b
bool
)
Tristate
{
if
b
{
return
True
}
else
{
return
False
}
}
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