mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 14:23:37 +00:00
Merge pull request #22736 from resouer/fix-util-dev
Auto commit by PR queue bot
This commit is contained in:
commit
4af38b52b9
@ -32,7 +32,7 @@ import (
|
|||||||
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
||||||
"k8s.io/kubernetes/pkg/master/ports"
|
"k8s.io/kubernetes/pkg/master/ports"
|
||||||
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util/config"
|
||||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -74,7 +74,7 @@ type APIServer struct {
|
|||||||
OIDCIssuerURL string
|
OIDCIssuerURL string
|
||||||
OIDCUsernameClaim string
|
OIDCUsernameClaim string
|
||||||
OIDCGroupsClaim string
|
OIDCGroupsClaim string
|
||||||
RuntimeConfig util.ConfigurationMap
|
RuntimeConfig config.ConfigurationMap
|
||||||
SSHKeyfile string
|
SSHKeyfile string
|
||||||
SSHUser string
|
SSHUser string
|
||||||
ServiceAccountKeyFile string
|
ServiceAccountKeyFile string
|
||||||
@ -106,7 +106,7 @@ func NewAPIServer() *APIServer {
|
|||||||
EventTTL: 1 * time.Hour,
|
EventTTL: 1 * time.Hour,
|
||||||
MasterCount: 1,
|
MasterCount: 1,
|
||||||
MasterServiceNamespace: api.NamespaceDefault,
|
MasterServiceNamespace: api.NamespaceDefault,
|
||||||
RuntimeConfig: make(util.ConfigurationMap),
|
RuntimeConfig: make(config.ConfigurationMap),
|
||||||
StorageVersions: registered.AllPreferredGroupVersions(),
|
StorageVersions: registered.AllPreferredGroupVersions(),
|
||||||
DefaultStorageVersions: registered.AllPreferredGroupVersions(),
|
DefaultStorageVersions: registered.AllPreferredGroupVersions(),
|
||||||
KubeletConfig: kubeletclient.KubeletClientConfig{
|
KubeletConfig: kubeletclient.KubeletClientConfig{
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||||
"k8s.io/kubernetes/pkg/master/ports"
|
"k8s.io/kubernetes/pkg/master/ports"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
|
"k8s.io/kubernetes/pkg/util/config"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
@ -52,8 +53,8 @@ type KubeletServer struct {
|
|||||||
ChaosChance float64
|
ChaosChance float64
|
||||||
// Crash immediately, rather than eating panics.
|
// Crash immediately, rather than eating panics.
|
||||||
ReallyCrashForTesting bool
|
ReallyCrashForTesting bool
|
||||||
SystemReserved util.ConfigurationMap
|
SystemReserved config.ConfigurationMap
|
||||||
KubeReserved util.ConfigurationMap
|
KubeReserved config.ConfigurationMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKubeletServer will create a new KubeletServer with default values.
|
// NewKubeletServer will create a new KubeletServer with default values.
|
||||||
@ -62,8 +63,8 @@ func NewKubeletServer() *KubeletServer {
|
|||||||
AuthPath: util.NewStringFlag("/var/lib/kubelet/kubernetes_auth"), // deprecated
|
AuthPath: util.NewStringFlag("/var/lib/kubelet/kubernetes_auth"), // deprecated
|
||||||
KubeConfig: util.NewStringFlag("/var/lib/kubelet/kubeconfig"),
|
KubeConfig: util.NewStringFlag("/var/lib/kubelet/kubeconfig"),
|
||||||
|
|
||||||
SystemReserved: make(util.ConfigurationMap),
|
SystemReserved: make(config.ConfigurationMap),
|
||||||
KubeReserved: make(util.ConfigurationMap),
|
KubeReserved: make(config.ConfigurationMap),
|
||||||
KubeletConfiguration: componentconfig.KubeletConfiguration{
|
KubeletConfiguration: componentconfig.KubeletConfiguration{
|
||||||
Address: "0.0.0.0",
|
Address: "0.0.0.0",
|
||||||
CAdvisorPort: 4194,
|
CAdvisorPort: 4194,
|
||||||
@ -181,7 +182,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.StringVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers")
|
fs.StringVar(&s.ClusterDNS, "cluster-dns", s.ClusterDNS, "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers")
|
||||||
fs.DurationVar(&s.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'")
|
fs.DurationVar(&s.StreamingConnectionIdleTimeout.Duration, "streaming-connection-idle-timeout", s.StreamingConnectionIdleTimeout.Duration, "Maximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: '5m'")
|
||||||
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
||||||
bindableNodeLabels := util.ConfigurationMap(s.NodeLabels)
|
bindableNodeLabels := config.ConfigurationMap(s.NodeLabels)
|
||||||
fs.Var(&bindableNodeLabels, "node-labels", "<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must be key=value pairs separated by ','.")
|
fs.Var(&bindableNodeLabels, "node-labels", "<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must be key=value pairs separated by ','.")
|
||||||
fs.DurationVar(&s.ImageMinimumGCAge.Duration, "minimum-image-ttl-duration", s.ImageMinimumGCAge.Duration, "Minimum age for a unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'. Default: '2m'")
|
fs.DurationVar(&s.ImageMinimumGCAge.Duration, "minimum-image-ttl-duration", s.ImageMinimumGCAge.Duration, "Minimum age for a unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'. Default: '2m'")
|
||||||
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
||||||
|
@ -59,6 +59,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/server"
|
"k8s.io/kubernetes/pkg/kubelet/server"
|
||||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
|
utilconfig "k8s.io/kubernetes/pkg/util/config"
|
||||||
"k8s.io/kubernetes/pkg/util/configz"
|
"k8s.io/kubernetes/pkg/util/configz"
|
||||||
"k8s.io/kubernetes/pkg/util/crypto"
|
"k8s.io/kubernetes/pkg/util/crypto"
|
||||||
"k8s.io/kubernetes/pkg/util/flock"
|
"k8s.io/kubernetes/pkg/util/flock"
|
||||||
@ -876,7 +877,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
|
|||||||
return k, pc, nil
|
return k, pc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseReservation(kubeReserved, systemReserved util.ConfigurationMap) (*kubetypes.Reservation, error) {
|
func parseReservation(kubeReserved, systemReserved utilconfig.ConfigurationMap) (*kubetypes.Reservation, error) {
|
||||||
reservation := new(kubetypes.Reservation)
|
reservation := new(kubetypes.Reservation)
|
||||||
if rl, err := parseResourceList(kubeReserved); err != nil {
|
if rl, err := parseResourceList(kubeReserved); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -891,7 +892,7 @@ func parseReservation(kubeReserved, systemReserved util.ConfigurationMap) (*kube
|
|||||||
return reservation, nil
|
return reservation, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseResourceList(m util.ConfigurationMap) (api.ResourceList, error) {
|
func parseResourceList(m utilconfig.ConfigurationMap) (api.ResourceList, error) {
|
||||||
rl := make(api.ResourceList)
|
rl := make(api.ResourceList)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
switch api.ResourceName(k) {
|
switch api.ResourceName(k) {
|
||||||
|
@ -2195,7 +2195,7 @@ _kubectl_config_view()
|
|||||||
flags_completion=()
|
flags_completion=()
|
||||||
|
|
||||||
flags+=("--flatten")
|
flags+=("--flatten")
|
||||||
flags+=("--merge")
|
flags+=("--merge=")
|
||||||
flags+=("--minify")
|
flags+=("--minify")
|
||||||
flags+=("--no-headers")
|
flags+=("--no-headers")
|
||||||
flags+=("--output=")
|
flags+=("--output=")
|
||||||
@ -2249,8 +2249,8 @@ _kubectl_config_set-cluster()
|
|||||||
|
|
||||||
flags+=("--api-version=")
|
flags+=("--api-version=")
|
||||||
flags+=("--certificate-authority=")
|
flags+=("--certificate-authority=")
|
||||||
flags+=("--embed-certs")
|
flags+=("--embed-certs=")
|
||||||
flags+=("--insecure-skip-tls-verify")
|
flags+=("--insecure-skip-tls-verify=")
|
||||||
flags+=("--server=")
|
flags+=("--server=")
|
||||||
flags+=("--alsologtostderr")
|
flags+=("--alsologtostderr")
|
||||||
flags+=("--client-certificate=")
|
flags+=("--client-certificate=")
|
||||||
@ -2288,7 +2288,7 @@ _kubectl_config_set-credentials()
|
|||||||
|
|
||||||
flags+=("--client-certificate=")
|
flags+=("--client-certificate=")
|
||||||
flags+=("--client-key=")
|
flags+=("--client-key=")
|
||||||
flags+=("--embed-certs")
|
flags+=("--embed-certs=")
|
||||||
flags+=("--password=")
|
flags+=("--password=")
|
||||||
flags+=("--token=")
|
flags+=("--token=")
|
||||||
flags+=("--username=")
|
flags+=("--username=")
|
||||||
|
@ -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 {
|
|||||||
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
|
||||||
|
@ -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 {
|
|||||||
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 (
|
||||||
|
@ -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
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/storage/etcd/metrics"
|
"k8s.io/kubernetes/pkg/storage/etcd/metrics"
|
||||||
etcdutil "k8s.io/kubernetes/pkg/storage/etcd/util"
|
etcdutil "k8s.io/kubernetes/pkg/storage/etcd/util"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
|
utilcache "k8s.io/kubernetes/pkg/util/cache"
|
||||||
utilnet "k8s.io/kubernetes/pkg/util/net"
|
utilnet "k8s.io/kubernetes/pkg/util/net"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
"k8s.io/kubernetes/pkg/watch"
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ func NewEtcdStorage(client etcd.Client, codec runtime.Codec, prefix string, quor
|
|||||||
copier: api.Scheme,
|
copier: api.Scheme,
|
||||||
pathPrefix: path.Join("/", prefix),
|
pathPrefix: path.Join("/", prefix),
|
||||||
quorum: quorum,
|
quorum: quorum,
|
||||||
cache: util.NewCache(maxEtcdCacheEntries),
|
cache: utilcache.NewCache(maxEtcdCacheEntries),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +156,7 @@ type etcdHelper struct {
|
|||||||
// support multi-object transaction that will result in many objects with the same index.
|
// support multi-object transaction that will result in many objects with the same index.
|
||||||
// Number of entries stored in the cache is controlled by maxEtcdCacheEntries constant.
|
// Number of entries stored in the cache is controlled by maxEtcdCacheEntries constant.
|
||||||
// TODO: Measure how much this cache helps after the conversion code is optimized.
|
// TODO: Measure how much this cache helps after the conversion code is optimized.
|
||||||
cache util.Cache
|
cache utilcache.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
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"
|
|
||||||
}
|
|
2
pkg/util/cache.go → pkg/util/cache/cache.go
vendored
2
pkg/util/cache.go → pkg/util/cache/cache.go
vendored
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package util
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package util
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package util
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
83
pkg/util/flag/tristate.go
Normal file
83
pkg/util/flag/tristate.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user