From fce5068f04ad3e0b3d51b5aadfd58ddb05e58be8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 20 Jan 2024 13:42:42 -0600 Subject: [PATCH] trying to make this work again Signed-off-by: Jeff Carr --- flags.go | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/flags.go b/flags.go index 60e9730..5ffc679 100644 --- a/flags.go +++ b/flags.go @@ -93,7 +93,7 @@ func SetDefaults() { } } -// protects against panic() by making sure it exists. +// simply protects against panic() by making sure it exists. func (f *LogFlag) Ok() bool { if f == nil {return false} return true @@ -139,6 +139,20 @@ func (f *LogFlag) Get() bool { return f.b } +/* +func (f *LogFlag) Set(b bool) { + if ! f.Ok() {} + f.b = b +} +*/ + +// probably a better name than Get() +// switch to this +func (f *LogFlag) Bool() bool { + if ! f.Ok() {return false} + return f.b +} + // returns the name of the flag func (f *LogFlag) GetName() string { if ! f.Ok() {return ""} @@ -157,6 +171,12 @@ func (f *LogFlag) GetDesc() string { return f.desc } +// returns the description of the flag +func (f *LogFlag) GetDefault() bool { + if ! f.Ok() {return false} + return f.orig +} + // register a variable name from a subsystem // inspired by Alex Flint // set the Default value at the time of registration @@ -185,34 +205,3 @@ func (f *LogFlag) Set(b bool) { f.b = b Info("Set() f.b is now", f.b) } - -/* -func Set(subsystem string, name string, b bool) { - flagsMutex.Lock() - defer flagsMutex.Unlock() - Verbose("log.Set() TODO find var:", "(" + subsystem + ")", name, "=", b) - for _, f := range flags { - Verbose("log.Set() ", "(" + f.subsystem + ")", f.name, "=", f.b, ":", f.desc) - if (subsystem == f.subsystem) && (name == f.name) { - Verbose("log.Set() FOUND ", f) - f.b = b - return - } - } - -} - -func Get(subsystem string, name string) bool { - flagsMutex.Lock() - defer flagsMutex.Unlock() - Verbose("log.Get() TODO find var:", "(" + subsystem + ")", name) - for _, f := range flags { - Verbose("log.Get() ", "(" + f.subsystem + ")", f.name, "=", f.b, ":", f.desc) - if (subsystem == f.subsystem) && (name == f.name) { - Verbose("log.Get() FOUND ", f) - return f.b - } - } - return false -} -*/