1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Just add some code doc around the use of AddXXX func to avoid any confusion

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-08-07 08:03:59 -07:00
parent b9094633f3
commit 592908c0f5

View file

@ -38,6 +38,7 @@ func NewBFlags() *BFlags {
} }
// AddBool adds a bool flag to BFlags // AddBool adds a bool flag to BFlags
// Note, any error will be generated when Parse() is called (see Parse).
func (bf *BFlags) AddBool(name string, def bool) *Flag { func (bf *BFlags) AddBool(name string, def bool) *Flag {
flag := bf.addFlag(name, boolType) flag := bf.addFlag(name, boolType)
if flag == nil { if flag == nil {
@ -52,6 +53,7 @@ func (bf *BFlags) AddBool(name string, def bool) *Flag {
} }
// AddString adds a string flag to BFlags // AddString adds a string flag to BFlags
// Note, any error will be generated when Parse() is called (see Parse).
func (bf *BFlags) AddString(name string, def string) *Flag { func (bf *BFlags) AddString(name string, def string) *Flag {
flag := bf.addFlag(name, stringType) flag := bf.addFlag(name, stringType)
if flag == nil { if flag == nil {
@ -61,6 +63,9 @@ func (bf *BFlags) AddString(name string, def string) *Flag {
return flag return flag
} }
// addFlag is a generic func used by the other AddXXX() func
// to add a new flag to the BFlags struct.
// Note, any error will be generated when Parse() is called (see Parse).
func (bf *BFlags) addFlag(name string, flagType FlagType) *Flag { func (bf *BFlags) addFlag(name string, flagType FlagType) *Flag {
if _, ok := bf.flags[name]; ok { if _, ok := bf.flags[name]; ok {
bf.Err = fmt.Errorf("Duplicate flag defined: %s", name) bf.Err = fmt.Errorf("Duplicate flag defined: %s", name)
@ -94,7 +99,14 @@ func (fl *Flag) IsTrue() bool {
return fl.Value == "true" return fl.Value == "true"
} }
// Parse parses and checks if the BFlags is valid // Parse parses and checks if the BFlags is valid.
// Any error noticed during the AddXXX() funcs will be generated/returned
// here. We do this because an error during AddXXX() is more like a
// compile time error so it doesn't matter too much when we stop our
// processing as long as we do stop it, so this allows the code
// around AddXXX() to be just:
// defFlag := AddString("desription", "")
// w/o needing to add an if-statement around each one.
func (bf *BFlags) Parse() error { func (bf *BFlags) Parse() error {
// If there was an error while defining the possible flags // If there was an error while defining the possible flags
// go ahead and bubble it back up here since we didn't do it // go ahead and bubble it back up here since we didn't do it