lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 2136977ae685beb3504930c4f1a97e8837ad56fd
parent 1eaf82cb895227ff970eef5237af22026158cbd6
Author: Sean Enck <sean@ttypty.com>
Date:   Mon,  2 Jun 2025 22:21:53 -0400

remaining util -> reflect

Diffstat:
Minternal/app/completions/core_test.go | 4++--
Minternal/output/json.go | 4++--
Minternal/platform/core.go | 4++--
Ainternal/reflect/core.go | 19+++++++++++++++++++
Ainternal/reflect/core_test.go | 20++++++++++++++++++++
Dinternal/util/reflect.go | 19-------------------
Dinternal/util/reflect_test.go | 20--------------------
7 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/internal/app/completions/core_test.go b/internal/app/completions/core_test.go @@ -8,7 +8,7 @@ import ( "testing" "git.sr.ht/~enckse/lockbox/internal/app/completions" - "git.sr.ht/~enckse/lockbox/internal/util" + "git.sr.ht/~enckse/lockbox/internal/reflect" ) func TestCompletions(t *testing.T) { @@ -28,7 +28,7 @@ func TestConditionals(t *testing.T) { if len(c.Exported) != len(need) || fmt.Sprintf("%v", c.Exported) != fmt.Sprintf("%v", need) { t.Errorf("invalid exports: %v", c.Exported) } - fields := util.ListFields(c.Not) + fields := reflect.ListFields(c.Not) if len(fields) != len(need)+1 { t.Errorf("invalid fields: %v", fields) } diff --git a/internal/output/json.go b/internal/output/json.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "git.sr.ht/~enckse/lockbox/internal/util" + "git.sr.ht/~enckse/lockbox/internal/reflect" ) // JSONModes are the JSON data output types for exporting/output of values @@ -29,7 +29,7 @@ type ( // List will list the output modes on the struct func (p JSONTypes) List() []string { - return util.ListFields(p) + return reflect.ListFields(p) } // ParseJSONMode handles detecting the JSON output mode diff --git a/internal/platform/core.go b/internal/platform/core.go @@ -7,7 +7,7 @@ import ( "os/exec" "strings" - "git.sr.ht/~enckse/lockbox/internal/util" + "git.sr.ht/~enckse/lockbox/internal/reflect" ) // Systems are the known platforms for lockbox @@ -35,7 +35,7 @@ type ( // List will list the platform types on the struct func (p SystemTypes) List() []string { - return util.ListFields(p) + return reflect.ListFields(p) } // NewSystem gets a new system platform. diff --git a/internal/reflect/core.go b/internal/reflect/core.go @@ -0,0 +1,19 @@ +// Package reflect has reflection helpers +package reflect + +import ( + "fmt" + "reflect" + "sort" +) + +// ListFields will get the values of strings on an "all string" struct +func ListFields(p any) []string { + v := reflect.ValueOf(p) + var vals []string + for i := range v.NumField() { + vals = append(vals, fmt.Sprintf("%v", v.Field(i).Interface())) + } + sort.Strings(vals) + return vals +} diff --git a/internal/reflect/core_test.go b/internal/reflect/core_test.go @@ -0,0 +1,20 @@ +package reflect_test + +import ( + "fmt" + "testing" + + "git.sr.ht/~enckse/lockbox/internal/reflect" +) + +type mock struct { + Name string + Field string +} + +func TestListFields(t *testing.T) { + fields := reflect.ListFields(mock{"abc", "xyz"}) + if len(fields) != 2 || fmt.Sprintf("%v", fields) != "[abc xyz]" { + t.Errorf("invalid fields: %v", fields) + } +} diff --git a/internal/util/reflect.go b/internal/util/reflect.go @@ -1,19 +0,0 @@ -// Package util has reflection helpers -package util - -import ( - "fmt" - "reflect" - "sort" -) - -// ListFields will get the values of strings on an "all string" struct -func ListFields(p any) []string { - v := reflect.ValueOf(p) - var vals []string - for i := range v.NumField() { - vals = append(vals, fmt.Sprintf("%v", v.Field(i).Interface())) - } - sort.Strings(vals) - return vals -} diff --git a/internal/util/reflect_test.go b/internal/util/reflect_test.go @@ -1,20 +0,0 @@ -package util_test - -import ( - "fmt" - "testing" - - "git.sr.ht/~enckse/lockbox/internal/util" -) - -type mock struct { - Name string - Field string -} - -func TestListFields(t *testing.T) { - fields := util.ListFields(mock{"abc", "xyz"}) - if len(fields) != 2 || fmt.Sprintf("%v", fields) != "[abc xyz]" { - t.Errorf("invalid fields: %v", fields) - } -}