From f269deb99cee656f28b4ee5f934ea6243ee1d400 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Mon, 10 Jun 2024 23:30:17 -0700 Subject: [PATCH] update toml_pretty --- Cargo.lock | 4 +- Cargo.toml | 2 +- bin/core/src/api/read/toml.rs | 124 ++++++++-------------------------- 3 files changed, 31 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f56e9f708..f981dcfb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3822,9 +3822,9 @@ dependencies = [ [[package]] name = "toml_pretty" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd6d77389405b3ff40a5f945888efc02cddcf932ebd33867a5ebc49806fc901" +checksum = "6c52247186037974d6547ab230c76bee9b0d777841189ec5b3eea4489cca2799" dependencies = [ "ordered_hash_map", "serde", diff --git a/Cargo.toml b/Cargo.toml index 09a67d4b9..791b327fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ partial_derive2 = "0.4.3" derive_variants = "1.0.0" mongo_indexed = "0.3.0" resolver_api = "1.1.0" -toml_pretty = "1.0.3" +toml_pretty = "1.1.0" parse_csl = "0.1.0" mungos = "0.5.6" svi = "1.0.1" diff --git a/bin/core/src/api/read/toml.rs b/bin/core/src/api/read/toml.rs index 67646eef1..5e8aae143 100644 --- a/bin/core/src/api/read/toml.rs +++ b/bin/core/src/api/read/toml.rs @@ -542,20 +542,18 @@ fn serialize_resources_toml( ) -> anyhow::Result { let mut res = String::new(); + let options = toml_pretty::Options::default() + .tab(" ") + .skip_empty_string(true); + for server in &resources.servers { if !res.is_empty() { res.push_str("\n\n##\n\n"); } res.push_str("[[server]]\n"); res.push_str( - &toml_pretty::to_string( - &server, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize servers to toml")?, + &toml_pretty::to_string(&server, options) + .context("failed to serialize servers to toml")?, ); } @@ -606,14 +604,8 @@ fn serialize_resources_toml( ); } res.push_str( - &toml_pretty::to_string( - &parsed, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize deployments to toml")?, + &toml_pretty::to_string(&parsed, options) + .context("failed to serialize deployments to toml")?, ); } @@ -648,14 +640,8 @@ fn serialize_resources_toml( } res.push_str("[[build]]\n"); res.push_str( - &toml_pretty::to_string( - &parsed, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize builds to toml")?, + &toml_pretty::to_string(&parsed, options) + .context("failed to serialize builds to toml")?, ); } @@ -665,14 +651,8 @@ fn serialize_resources_toml( } res.push_str("[[repo]]\n"); res.push_str( - &toml_pretty::to_string( - &repo, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize repos to toml")?, + &toml_pretty::to_string(&repo, options) + .context("failed to serialize repos to toml")?, ); } @@ -695,27 +675,15 @@ fn serialize_resources_toml( res.push_str("[[procedure]]\n"); res.push_str( - &toml_pretty::to_string( - &parsed, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize procedures to toml")?, + &toml_pretty::to_string(&parsed, options) + .context("failed to serialize procedures to toml")?, ); for stage in stages { res.push_str("\n\n[[procedure.config.stage]]\n"); res.push_str( - &toml_pretty::to_string( - stage, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize procedures to toml")?, + &toml_pretty::to_string(stage, options) + .context("failed to serialize procedures to toml")?, ); } } @@ -726,14 +694,8 @@ fn serialize_resources_toml( } res.push_str("[[alerter]]\n"); res.push_str( - &toml_pretty::to_string( - &alerter, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize alerters to toml")?, + &toml_pretty::to_string(&alerter, options) + .context("failed to serialize alerters to toml")?, ); } @@ -743,14 +705,8 @@ fn serialize_resources_toml( } res.push_str("[[builder]]\n"); res.push_str( - &toml_pretty::to_string( - &builder, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize builders to toml")?, + &toml_pretty::to_string(&builder, options) + .context("failed to serialize builders to toml")?, ); } @@ -760,14 +716,8 @@ fn serialize_resources_toml( } res.push_str("[[server_template]]\n"); res.push_str( - &toml_pretty::to_string( - &server_template, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize server_templates to toml")?, + &toml_pretty::to_string(&server_template, options) + .context("failed to serialize server_templates to toml")?, ); } @@ -777,14 +727,8 @@ fn serialize_resources_toml( } res.push_str("[[resource_sync]]\n"); res.push_str( - &toml_pretty::to_string( - &resource_sync, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize resource_syncs to toml")?, + &toml_pretty::to_string(&resource_sync, options) + .context("failed to serialize resource_syncs to toml")?, ); } @@ -794,14 +738,8 @@ fn serialize_resources_toml( } res.push_str("[[variable]]\n"); res.push_str( - &toml_pretty::to_string( - &variable, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize variables to toml")?, + &toml_pretty::to_string(&variable, options) + .context("failed to serialize variables to toml")?, ); } @@ -811,14 +749,8 @@ fn serialize_resources_toml( } res.push_str("[[user_group]]\n"); res.push_str( - &toml_pretty::to_string( - &user_group, - toml_pretty::Options::builder() - .tab(" ") - .skip_empty_string(true) - .build(), - ) - .context("failed to serialize user_groups to toml")?, + &toml_pretty::to_string(&user_group, options) + .context("failed to serialize user_groups to toml")?, ); }