mirror of
https://github.com/containers/podman.git
synced 2025-10-18 03:33:32 +08:00
quadlet: Rename parser.LookupBoolean to LookupBooleanWithDefault
We add a regular LookupBoolean that can fail lookups, which is used by the WithDefault version. We want to use this directly later in some places. It is fina to change API here because this has not been in a release yet. Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
@ -615,16 +615,26 @@ func (f *UnitFile) Lookup(groupName string, key string) (string, bool) {
|
||||
}
|
||||
|
||||
// Lookup the last instance of a key and convert the value to a bool
|
||||
func (f *UnitFile) LookupBoolean(groupName string, key string, defaultValue bool) bool {
|
||||
func (f *UnitFile) LookupBoolean(groupName string, key string) (bool, bool) {
|
||||
v, ok := f.Lookup(groupName, key)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
return false, false
|
||||
}
|
||||
|
||||
return strings.EqualFold(v, "1") ||
|
||||
strings.EqualFold(v, "yes") ||
|
||||
strings.EqualFold(v, "true") ||
|
||||
strings.EqualFold(v, "on")
|
||||
strings.EqualFold(v, "on"), true
|
||||
}
|
||||
|
||||
// Lookup the last instance of a key and convert the value to a bool
|
||||
func (f *UnitFile) LookupBooleanWithDefault(groupName string, key string, defaultValue bool) bool {
|
||||
v, ok := f.LookupBoolean(groupName, key)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
/* Mimics strol, which is what systemd uses */
|
||||
|
Reference in New Issue
Block a user