| 1 | Patch-Source: https://github.com/oriontvv/convfmt/pull/193
|
| 2 | --
|
| 3 | From 8c2d2f62071d0dc4e17cb6536cdab2bd60bd598a Mon Sep 17 00:00:00 2001
|
| 4 | From: Jakub Jirutka <[email protected]>
|
| 5 | Date: Sat, 23 May 2026 23:55:49 +0200
|
| 6 | Subject: [PATCH] make hocon optional
|
| 7 |
|
| 8 | hocon crate is unmaintained since 2023 and it pulls a huge dependency
|
| 9 | bloat.
|
| 10 | ---
|
| 11 | Cargo.toml | 6 +++++-
|
| 12 | src/lib.rs | 36 +++++++++++++++++++++++++++---------
|
| 13 | 2 files changed, 32 insertions(+), 10 deletions(-)
|
| 14 |
|
| 15 | diff --git a/Cargo.toml b/Cargo.toml
|
| 16 | index 45c95ed..b218757 100644
|
| 17 | |
| 18 | |
| 19 | @@ -13,13 +13,17 @@ categories = ["command-line-utilities"]
|
| 20 |
|
| 21 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
| 22 |
|
| 23 | +[features]
|
| 24 | +default = ["hocon"]
|
| 25 | +hocon = ["dep:hocon"]
|
| 26 | +
|
| 27 | [dependencies]
|
| 28 | anyhow = "1.0.100"
|
| 29 | bson = { version = "3.1.0", features = ["serde"] }
|
| 30 | clap = { version = "4.5.53", features = ["derive"] }
|
| 31 | csv = "1.4.0"
|
| 32 | hjson = "1.1.0"
|
| 33 | -hocon = { version = "0.9.0", features = ["serde-support"] }
|
| 34 | +hocon = { version = "0.9.0", features = ["serde-support"], optional = true }
|
| 35 | json5 = "1.3.0"
|
| 36 | linked-hash-map = "0.5.6"
|
| 37 | plist = "1.8.0"
|
| 38 | diff --git a/src/lib.rs b/src/lib.rs
|
| 39 | index e0530ae..030f570 100644
|
| 40 | |
| 41 | |
| 42 | @@ -1,4 +1,5 @@
|
| 43 | mod csv_value;
|
| 44 | +#[cfg(feature = "hocon")]
|
| 45 | mod hocon_value;
|
| 46 | mod jsonl_value;
|
| 47 | mod xml_value;
|
| 48 | @@ -6,9 +7,10 @@ mod xml_value;
|
| 49 | use anyhow::Result;
|
| 50 | use serde::Serialize;
|
| 51 |
|
| 52 | +#[cfg(feature = "hocon")]
|
| 53 | +use crate::hocon_value::{HoconWrapper, load_hocon};
|
| 54 | use crate::{
|
| 55 | csv_value::{CsvWrapper, json_to_csv, load_csv},
|
| 56 | - hocon_value::{HoconWrapper, load_hocon},
|
| 57 | jsonl_value::{JsonlWrapper, json_to_jsonl, load_jsonl},
|
| 58 | xml_value::{XmlWrapper, json_to_xml, load_xml},
|
| 59 | };
|
| 60 | @@ -18,6 +20,7 @@ pub enum Format {
|
| 61 | Bson,
|
| 62 | Csv,
|
| 63 | Hjson,
|
| 64 | + #[cfg(feature = "hocon")]
|
| 65 | Hocon,
|
| 66 | Json,
|
| 67 | Json5,
|
| 68 | @@ -36,6 +39,7 @@ pub enum Value {
|
| 69 | Bson(bson::Bson),
|
| 70 | Csv(CsvWrapper),
|
| 71 | Hjson(serde_hjson::Value),
|
| 72 | + #[cfg(feature = "hocon")]
|
| 73 | Hocon(HoconWrapper),
|
| 74 | Json(serde_json::Value),
|
| 75 | Json5(serde_json::Value),
|
| 76 | @@ -53,6 +57,7 @@ pub fn load_input(input: &[u8], format: Format) -> Result<Value> {
|
| 77 | Format::Bson => Value::Bson(bson::deserialize_from_slice(input)?),
|
| 78 | Format::Csv => Value::Csv(load_csv(input)?),
|
| 79 | Format::Hjson => Value::Hjson(serde_hjson::from_slice(input)?),
|
| 80 | + #[cfg(feature = "hocon")]
|
| 81 | Format::Hocon => Value::Hocon(load_hocon(input)?),
|
| 82 | Format::Json => Value::Json(serde_json::from_slice(input)?),
|
| 83 | Format::Json5 => Value::Json5(json5::from_str(str::from_utf8(input)?)?),
|
| 84 | @@ -81,7 +86,9 @@ pub fn dump_value(value: &Value, format: Format, is_compact: bool) -> Result<Vec
|
| 85 | json_to_csv(&json_dumped)?
|
| 86 | }
|
| 87 | (Format::Hjson, _) => serde_hjson::to_vec(value)?,
|
| 88 | + #[cfg(feature = "hocon")]
|
| 89 | (Format::Hocon, true) => serde_json::to_vec(value)?,
|
| 90 | + #[cfg(feature = "hocon")]
|
| 91 | (Format::Hocon, false) => serde_json::to_vec_pretty(value)?,
|
| 92 | (Format::Json, true) => serde_json::to_vec(value)?,
|
| 93 | (Format::Json, false) => serde_json::to_vec_pretty(value)?,
|
| 94 | @@ -136,6 +143,7 @@ mod tests {
|
| 95 | the_answer: 42
|
| 96 | }"#
|
| 97 | }
|
| 98 | + #[cfg(feature = "hocon")]
|
| 99 | (Format::Hocon, _) => {
|
| 100 | r#"
|
| 101 | array: [a,b]
|
| 102 | @@ -246,7 +254,6 @@ the_answer: 42
|
| 103 | #[case(Format::Json5, Format::Json, false)]
|
| 104 | #[case(Format::Json, Format::Bson, false)]
|
| 105 | #[case(Format::Bson, Format::Json5, true)]
|
| 106 | - #[case(Format::Hocon, Format::Json, false)]
|
| 107 | #[case(Format::Xml, Format::Yaml, false)]
|
| 108 | #[case(Format::Toml, Format::Xml, true)]
|
| 109 | #[case(Format::Toml, Format::Hjson, true)]
|
| 110 | @@ -273,6 +280,12 @@ the_answer: 42
|
| 111 | assert_eq!(output, expected_output);
|
| 112 | }
|
| 113 |
|
| 114 | + #[cfg(feature = "hocon")]
|
| 115 | + #[test]
|
| 116 | + fn test_convert_formats_hocon() {
|
| 117 | + test_convert_formats(Format::Hocon, Format::Json, false);
|
| 118 | + }
|
| 119 | +
|
| 120 | #[rstest]
|
| 121 | #[case(
|
| 122 | Format::Csv,
|
| 123 | @@ -317,13 +330,6 @@ the_answer: 42
|
| 124 | "#,
|
| 125 | true
|
| 126 | )]
|
| 127 | - #[case(
|
| 128 | - Format::Hocon,
|
| 129 | - Format::Json,
|
| 130 | - r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#,
|
| 131 | - r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#,
|
| 132 | - true
|
| 133 | - )]
|
| 134 | #[case(
|
| 135 | Format::Json,
|
| 136 | Format::Json,
|
| 137 | @@ -363,4 +369,16 @@ the_answer: 42
|
| 138 |
|
| 139 | assert_eq!(output, expected_output);
|
| 140 | }
|
| 141 | +
|
| 142 | + #[cfg(feature = "hocon")]
|
| 143 | + #[test]
|
| 144 | + fn test_raw_convert_hocon() {
|
| 145 | + test_raw_convert(
|
| 146 | + Format::Hocon,
|
| 147 | + Format::Json,
|
| 148 | + r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#,
|
| 149 | + r#"{"age":55000,"immortal":true,"name":"Gendalf the \"White\"","power":50.0}"#,
|
| 150 | + true,
|
| 151 | + );
|
| 152 | + }
|
| 153 | }
|
| 154 | --
|
| 155 | 2.52.0
|
| 156 |
|