Blame vendor/github.com/vmware/govmomi/govc/flags/optional_bool.go
|
Packit Service |
4d2de5 |
/*
|
|
Packit Service |
4d2de5 |
Copyright (c) 2015 VMware, Inc. All Rights Reserved.
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit Service |
4d2de5 |
you may not use this file except in compliance with the License.
|
|
Packit Service |
4d2de5 |
You may obtain a copy of the License at
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
Unless required by applicable law or agreed to in writing, software
|
|
Packit Service |
4d2de5 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit Service |
4d2de5 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit Service |
4d2de5 |
See the License for the specific language governing permissions and
|
|
Packit Service |
4d2de5 |
limitations under the License.
|
|
Packit Service |
4d2de5 |
*/
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
package flags
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
import (
|
|
Packit Service |
4d2de5 |
"flag"
|
|
Packit Service |
4d2de5 |
"fmt"
|
|
Packit Service |
4d2de5 |
"strconv"
|
|
Packit Service |
4d2de5 |
)
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
type optionalBool struct {
|
|
Packit Service |
4d2de5 |
val **bool
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
func (b *optionalBool) Set(s string) error {
|
|
Packit Service |
4d2de5 |
v, err := strconv.ParseBool(s)
|
|
Packit Service |
4d2de5 |
*b.val = &v
|
|
Packit Service |
4d2de5 |
return err
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
func (b *optionalBool) Get() interface{} {
|
|
Packit Service |
4d2de5 |
if *b.val == nil {
|
|
Packit Service |
4d2de5 |
return nil
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
return **b.val
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
func (b *optionalBool) String() string {
|
|
Packit Service |
4d2de5 |
if b.val == nil || *b.val == nil {
|
|
Packit Service |
4d2de5 |
return "<nil>"
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
return fmt.Sprintf("%v", **b.val)
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
func (b *optionalBool) IsBoolFlag() bool { return true }
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// NewOptionalBool returns a flag.Value implementation where there is no default value.
|
|
Packit Service |
4d2de5 |
// This avoids sending a default value over the wire as using flag.BoolVar() would.
|
|
Packit Service |
4d2de5 |
func NewOptionalBool(v **bool) flag.Value {
|
|
Packit Service |
4d2de5 |
return &optionalBool{v}
|
|
Packit Service |
4d2de5 |
}
|