Notgnoshi / herostratus

An ancient Greek known for seeking fame through crime and destruction. Also a Git repository achievements engine.
MIT License
0 stars 0 forks source link

Preserve order and comments in config file when adding a new repository #46

Open Notgnoshi opened 2 months ago

Notgnoshi commented 2 months ago
herostratus add --name herostratus-1 https://github.com/Notgnoshi/herostratus.git
herostratus add --name herostratus-2 https://github.com/Notgnoshi/herostratus.git --skip-clone

results in

[repositories.herostratus-1]
path = "git/Notgnoshi/herostratus.git"
url = "https://github.com/Notgnoshi/herostratus.git"

[repositories.herostratus-2]
path = "git/Notgnoshi/herostratus.git"
url = "https://github.com/Notgnoshi/herostratus.git"

sometimes and other times

[repositories.herostratus-2]
path = "git/Notgnoshi/herostratus.git"
url = "https://github.com/Notgnoshi/herostratus.git"

[repositories.herostratus-1]
path = "git/Notgnoshi/herostratus.git"
url = "https://github.com/Notgnoshi/herostratus.git"

I tried using toml_edit to sort the repositories keys, but it resulted in to_string() returning ... nothing

let mut document = toml_edit::ser::to_document(config)?;
for (key, value) in document.iter() {
    // just to demonstrate that the data *IS* there, it's just not getting serialized
    tracing.info!("key: {key:?} value: {value:?}");
}

document.sort_values();
document.set_dotted(true);

document.to_string() // this returns an empty string