Skip to content

Use mergeme to merge CLI config #452

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Use mergeme to merge CLI config #452

wants to merge 2 commits into from

Conversation

BD103
Copy link
Member

@BD103 BD103 commented May 20, 2025

Objective

mergeme is a little crate that I wrote1 that makes it easy to merge structures together. For example:

use mergeme::Merge;

#[derive(Merge)]
#[partial(PartialPerson)]
struct Person {
    name: String,
    age: u16,
    #[strategy(merge)]
    friends: Vec<String>,
}

let person = Person {
    name: "Janette".to_string(),
    age: 19,
    friends: vec!["Lou".to_string()],
};

// Change Janette's age to be 25 and add a friend, but preserve her original name.
let partial = PartialPerson {
    name: None,
    age: Some(25),
    friends: Some(vec!["Kylie".to_string()]),
};

let merged = person.merge(partial);

assert_eq!(merged.name, "Janette");
assert_eq!(merged.age, 25);
assert_eq!(merged.friends, ["Lou", "Kylie"]);

This PR greatly simplifies the API surface of CliConfig by offloading the merging logic to mergeme's derive macro.

Major Changes

CliConfig::for_package() and CliConfig::merged_from_metadata() have been combined into a single CliConfig::from_metadata() function that takes a &serde_json::Value for the [package.metadata] table2.

That should be the only visible change, and that's only API-related. The CLI should behave the same, but please be sure to test on actual projects with nested configuration to ensure it works!

Footnotes

  1. You can tell because there are more docs and comments than actual code >:D

  2. Not [package.metadata.bevy_cli], but just [package.metadata]. This is why the unit tests were changed in the way they were.

@BD103 BD103 added A-CLI Related to the main CLI and not a more specific subcommand C-Code-Quality An improvement of readability or quality D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review The PR needs to be reviewed before it can be merged labels May 20, 2025
@DaAlbrecht
Copy link
Collaborator

Excited for this!! Didnt have time to do a review just yet but i would wait with this for 0.2.0 as we have quite a lot of testing with the old system and this is a pretty major internal change.

@BD103
Copy link
Member Author

BD103 commented May 20, 2025

Excited for this!! Didnt have time to do a review just yet but i would wait with this for 0.2.0 as we have quite a lot of testing with the old system and this is a pretty major internal change.

Agreed, I'll mark this as blocked until the release

@BD103 BD103 added S-Blocked This cannot move forward until something else changes and removed S-Needs-Review The PR needs to be reviewed before it can be merged labels May 20, 2025
@BD103 BD103 added S-Needs-Review The PR needs to be reviewed before it can be merged and removed S-Blocked This cannot move forward until something else changes labels May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Related to the main CLI and not a more specific subcommand C-Code-Quality An improvement of readability or quality D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review The PR needs to be reviewed before it can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants