From cf571ad66188619ed35845eb40e68392cf61e59c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 28 Mar 2025 16:06:50 +0000 Subject: [PATCH] rc: In options/info make FieldName contain a "." if it should be nested Before this would have Output "FieldName": "ListenAddr" where it actually needs to be set in a sub object "HTTP". After this fix it outputs "FieldName": "HTTP.ListenAddr" to indicate "ListenAddr" needs to be set in the object "HTTP". --- docs/content/rc.md | 2 +- fs/config/configstruct/configstruct.go | 1 + fs/config/configstruct/configstruct_test.go | 22 ++++++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/content/rc.md b/docs/content/rc.md index 4f54bb170..7b7822868 100644 --- a/docs/content/rc.md +++ b/docs/content/rc.md @@ -432,7 +432,7 @@ format. Each block describes a single option. | Field | Type | Optional | Description | |-------|------|----------|-------------| | Name | string | N | name of the option in snake_case | -| FieldName | string | N | name of the field used in the rc - if blank use Name | +| FieldName | string | N | name of the field used in the rc - if blank use Name. May contain "." for nested fields. | | Help | string | N | help, started with a single sentence on a single line | | Groups | string | Y | groups this option belongs to - comma separated string for options classification | | Provider | string | Y | set to filter on provider | diff --git a/fs/config/configstruct/configstruct.go b/fs/config/configstruct/configstruct.go index e9535d716..7ad3f68b8 100644 --- a/fs/config/configstruct/configstruct.go +++ b/fs/config/configstruct/configstruct.go @@ -139,6 +139,7 @@ func Items(opt any) (items []Item, err error) { if hasTag { newItem.Name = configName + "_" + newItem.Name } + newItem.Field = fieldName + "." + newItem.Field items = append(items, newItem) } } else { diff --git a/fs/config/configstruct/configstruct_test.go b/fs/config/configstruct/configstruct_test.go index a268553f9..4e42a661b 100644 --- a/fs/config/configstruct/configstruct_test.go +++ b/fs/config/configstruct/configstruct_test.go @@ -100,17 +100,17 @@ func TestItemsNested(t *testing.T) { got, err := configstruct.Items(&in) require.NoError(t, err) want := []configstruct.Item{ - {Name: "a", Field: "A", Value: string("1")}, - {Name: "b", Field: "B", Value: string("2")}, - {Name: "sub_a", Field: "A", Value: string("3")}, - {Name: "sub_b", Field: "B", Value: string("4")}, - {Name: "spud_pie", Field: "PotatoPie", Value: string("yum")}, - {Name: "bean_stew", Field: "BeanStew", Value: true}, - {Name: "raisin_roll", Field: "RaisinRoll", Value: int(42)}, - {Name: "sausage_on_stick", Field: "SausageOnStick", Value: int64(101)}, - {Name: "forbidden_fruit", Field: "ForbiddenFruit", Value: uint(6)}, - {Name: "cooking_time", Field: "CookingTime", Value: fs.Duration(42 * time.Second)}, - {Name: "total_weight", Field: "TotalWeight", Value: fs.SizeSuffix(17 << 20)}, + {Name: "a", Field: "Conf.A", Value: string("1")}, + {Name: "b", Field: "Conf.B", Value: string("2")}, + {Name: "sub_a", Field: "Sub1.A", Value: string("3")}, + {Name: "sub_b", Field: "Sub1.B", Value: string("4")}, + {Name: "spud_pie", Field: "Sub2.PotatoPie", Value: string("yum")}, + {Name: "bean_stew", Field: "Sub2.BeanStew", Value: true}, + {Name: "raisin_roll", Field: "Sub2.RaisinRoll", Value: int(42)}, + {Name: "sausage_on_stick", Field: "Sub2.SausageOnStick", Value: int64(101)}, + {Name: "forbidden_fruit", Field: "Sub2.ForbiddenFruit", Value: uint(6)}, + {Name: "cooking_time", Field: "Sub2.CookingTime", Value: fs.Duration(42 * time.Second)}, + {Name: "total_weight", Field: "Sub2.TotalWeight", Value: fs.SizeSuffix(17 << 20)}, {Name: "c", Field: "C", Value: string("normal")}, {Name: "d", Field: "D", Value: fs.Tristate{Value: true, Valid: true}}, }