Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement merging overrides when grouping configs #288

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

DavidSGK
Copy link
Member

@DavidSGK DavidSGK commented Jan 18, 2024

In #284 we added config grouping which handled merging default values. This PR implements the merging of overrides from the source configs.
Precedence of overrides in the resulting grouped config is based on the input order.
Values of overrides with the same rule strings are merged together.

Given the source configs:

# config-a.star
export(
    Config(
        description = "Config A",
        default = "Hello, world!",
        overrides = [
            ("foo == \"val-1\"", "Goodbye!"),
            ("foo == \"val-2\"", "What?"),
        ],
    ),
)
# config-b.star
export(
    Config(
        description = "Config B",
        default = False,
        overrides = [
            ("foo == \"val-3\"", True),
            ("foo == \"val-1\"", True),
        ],
    ),
)
# config-c.star
export(
    Config(
        description = "Config C",
        default = 123,
        overrides = [
            ("foo == \"val-2\"", 456),
            ("foo == \"val-3\"", 789),
        ],
    ),
)

We get the grouped config:

default_config_v1beta1 = proto.package("default.config.v1beta1")

export(
    Config(
        description = "Grouped from config-a, config-b, config-c",
        default = default_config_v1beta1.Grouped(config_a = "Hello, world!", config_c = 123),
        overrides = [
            ("foo == \"val-1\"", default_config_v1beta1.Grouped(config_a = "Goodbye!", config_b = True)),
            ("foo == \"val-2\"", default_config_v1beta1.Grouped(config_a = "What?", config_c = 456)),
            ("foo == \"val-3\"", default_config_v1beta1.Grouped(config_b = True, config_c = 789)),
        ],
    ),
)

Also tested with string enum configs to confirm.

@DavidSGK DavidSGK self-assigned this Jan 18, 2024
@DavidSGK DavidSGK marked this pull request as ready for review January 18, 2024 22:15
@@ -592,6 +593,62 @@ func configGroup() *cobra.Command {
defaultValue.Set(mt.Descriptor().Fields().ByName(protoreflect.Name(protoFieldNames[i])), protoreflect.ValueOf(orig.Value))
}
newF.Value = defaultValue
// TODO: Should probably extract this/enum handling logic out for better code org...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't - it's used in one place

Base automatically changed from david-gen-enums to main January 18, 2024 23:22
@DavidSGK DavidSGK force-pushed the david-config-group-overrides branch from 5b71339 to d5af385 Compare January 18, 2024 23:23
@DavidSGK DavidSGK merged commit 88ff428 into main Jan 18, 2024
1 check passed
@DavidSGK DavidSGK deleted the david-config-group-overrides branch January 18, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants