From 2728224fa1b71cb72f8d2ab93c2c40d8804e6376 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Fri, 23 Dec 2022 10:16:59 +0100 Subject: [PATCH] feat: hint and error functions --- error.go | 13 +++++-------- help-util.go | 2 +- hint.go | 14 ++++++++++++++ mapping.go | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/error.go b/error.go index 91966f4..7086f98 100644 --- a/error.go +++ b/error.go @@ -20,19 +20,16 @@ func (s *Settings[C]) HasErrors() bool { return len(s.errors) > 0 } -func (s *Settings[C]) HasHint() bool { - return s.hint != "" -} - -func (s *Settings[C]) GetHint() string { - return s.hint -} - // Get all errors func (s *Settings[C]) Errors() []error { return s.errors } +func (s *Settings[C]) AddError(err error) *Settings[C] { + s.errors = append(s.errors, err) + return s +} + var WatchListNotInitializedError = errors.New("watch list not initialized") var MissingCommandError = errors.New("missing command") var NotParsedError = errors.New("flag set not parsed") diff --git a/help-util.go b/help-util.go index 3a153d0..c3512fd 100644 --- a/help-util.go +++ b/help-util.go @@ -96,7 +96,7 @@ func getFlagTable(f *flag.FlagSet) []string { // isZeroValue determines whether the string represents the zero // value for a flag. func isZeroValue(f *flag.Flag, value string) (ok bool, err error) { - // Build a zero value of the flag's Value type, and see if the + // Sync a zero value of the flag's Value type, and see if the // result of calling its String method equals the value passed in. // This works unless the Value type is itself an interface type. typ := reflect.TypeOf(f.Value) diff --git a/hint.go b/hint.go index e69de29..3b4f870 100644 --- a/hint.go +++ b/hint.go @@ -0,0 +1,14 @@ +package xflags + +func (s *Settings[C]) SetHint(hint string) *Settings[C] { + s.hint = hint + return s +} + +func (s *Settings[C]) HasHint() bool { + return s.hint != "" +} + +func (s *Settings[C]) GetHint() string { + return s.hint +} diff --git a/mapping.go b/mapping.go index 19a0b66..296973d 100644 --- a/mapping.go +++ b/mapping.go @@ -37,7 +37,7 @@ func (s *Settings[C]) assignValues(c cmd[C]) { flgs.Visit(func(f *flag.Flag) { name := f.Name - value := f.Value.String() + value := f.Value //.String() k, ok := c.tagMapping[name] if !ok { -- GitLab