Skip to content

Commit

Permalink
cargo: bump toml_edit to 0.22.22
Browse files Browse the repository at this point in the history
toml_edit now has separate immutable and mutable Document types. Other than
that, the API should be compatible.
  • Loading branch information
yuja committed Nov 21, 2024
1 parent e060ef2 commit 99c2698
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 35 deletions.
23 changes: 7 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ textwrap = "0.16.1"
thiserror = "1.0.69"
timeago = { version = "0.4.2", default-features = false }
tokio = { version = "1.41.1" }
toml_edit = { version = "0.19.15", features = ["serde"] }
toml_edit = { version = "0.22.22", features = ["serde"] }
tracing = "0.1.40"
tracing-chrome = "0.7.2"
tracing-subscriber = { version = "0.3.18", default-features = false, features = [
Expand Down
76 changes: 58 additions & 18 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ fn read_config_path(config_path: &Path) -> Result<config::Config, config::Config
.build()
}

fn read_config(path: &Path) -> Result<toml_edit::Document, CommandError> {
fn read_config(path: &Path) -> Result<toml_edit::ImDocument<String>, CommandError> {
let config_toml = std::fs::read_to_string(path).or_else(|err| {
match err.kind() {
// If config doesn't exist yet, read as empty and we'll write one.
Expand All @@ -605,7 +605,7 @@ fn read_config(path: &Path) -> Result<toml_edit::Document, CommandError> {
})
}

fn write_config(path: &Path, doc: &toml_edit::Document) -> Result<(), CommandError> {
fn write_config(path: &Path, doc: &toml_edit::DocumentMut) -> Result<(), CommandError> {
std::fs::write(path, doc.to_string()).map_err(|err| {
user_error_with_message(
format!("Failed to write file {path}", path = path.display()),
Expand All @@ -619,7 +619,7 @@ pub fn write_config_value_to_file(
value: toml_edit::Value,
path: &Path,
) -> Result<(), CommandError> {
let mut doc = read_config(path)?;
let mut doc = read_config(path)?.into_mut();

// Apply config value
let mut target_table = doc.as_table_mut();
Expand Down Expand Up @@ -655,7 +655,7 @@ pub fn remove_config_value_from_file(
key: &ConfigNamePathBuf,
path: &Path,
) -> Result<(), CommandError> {
let mut doc = read_config(path)?;
let mut doc = read_config(path)?.into_mut();

// Find target table
let mut key_iter = key.components();
Expand Down Expand Up @@ -975,23 +975,31 @@ mod tests {
// Note: "email" is alphabetized, before "name" from same layer.
insta::assert_debug_snapshot!(
layered_configs.resolved_config_values(&ConfigNamePathBuf::root()).unwrap(),
@r###"
@r#"
[
AnnotatedValue {
path: ConfigNamePathBuf(
[
Key {
key: "user",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
},
Key {
key: "email",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
Expand All @@ -1013,15 +1021,23 @@ mod tests {
Key {
key: "user",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
},
Key {
key: "name",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
Expand All @@ -1043,15 +1059,23 @@ mod tests {
Key {
key: "user",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
},
Key {
key: "email",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
Expand All @@ -1068,7 +1092,7 @@ mod tests {
is_overridden: false,
},
]
"###
"#
);
}

Expand Down Expand Up @@ -1099,23 +1123,31 @@ mod tests {
layered_configs
.resolved_config_values(&ConfigNamePathBuf::from_iter(["test-table1"]))
.unwrap(),
@r###"
@r#"
[
AnnotatedValue {
path: ConfigNamePathBuf(
[
Key {
key: "test-table1",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
},
Key {
key: "foo",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
Expand All @@ -1137,15 +1169,23 @@ mod tests {
Key {
key: "test-table1",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
},
Key {
key: "bar",
repr: None,
decor: Decor {
leaf_decor: Decor {
prefix: "default",
suffix: "default",
},
dotted_decor: Decor {
prefix: "default",
suffix: "default",
},
Expand All @@ -1162,7 +1202,7 @@ mod tests {
is_overridden: false,
},
]
"###
"#
);
}

Expand Down

0 comments on commit 99c2698

Please sign in to comment.