celq 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {celq-0.3.2 → celq-0.3.3}/CHANGELOG.md +12 -0
  2. {celq-0.3.2 → celq-0.3.3}/Cargo.lock +24 -1
  3. {celq-0.3.2 → celq-0.3.3}/Cargo.toml +4 -2
  4. {celq-0.3.2 → celq-0.3.3}/PKG-INFO +44 -3
  5. {celq-0.3.2 → celq-0.3.3}/README.md +43 -2
  6. {celq-0.3.2 → celq-0.3.3}/docs/installation_guide.md +42 -1
  7. {celq-0.3.2 → celq-0.3.3}/docs/manual.md +58 -3
  8. {celq-0.3.2 → celq-0.3.3}/pypi/README.md +43 -2
  9. {celq-0.3.2 → celq-0.3.3}/src/cli.rs +7 -0
  10. {celq-0.3.2 → celq-0.3.3}/src/json2cel.rs +17 -0
  11. {celq-0.3.2 → celq-0.3.3}/tests/golden.rs +103 -0
  12. {celq-0.3.2 → celq-0.3.3}/LICENSE-APACHE +0 -0
  13. {celq-0.3.2 → celq-0.3.3}/LICENSE-MIT +0 -0
  14. {celq-0.3.2 → celq-0.3.3}/docs/comparison_with_other_tools.md +0 -0
  15. {celq-0.3.2 → celq-0.3.3}/pypi/LICENSE-APACHE +0 -0
  16. {celq-0.3.2 → celq-0.3.3}/pypi/LICENSE-MIT +0 -0
  17. {celq-0.3.2 → celq-0.3.3}/pyproject.toml +0 -0
  18. {celq-0.3.2 → celq-0.3.3}/src/args2cel.rs +0 -0
  19. {celq-0.3.2 → celq-0.3.3}/src/args2cel_test.rs +0 -0
  20. {celq-0.3.2 → celq-0.3.3}/src/documentation.rs +0 -0
  21. {celq-0.3.2 → celq-0.3.3}/src/gron.rs +0 -0
  22. {celq-0.3.2 → celq-0.3.3}/src/gron_test.rs +0 -0
  23. {celq-0.3.2 → celq-0.3.3}/src/input_handler.rs +0 -0
  24. {celq-0.3.2 → celq-0.3.3}/src/input_handler_test.rs +0 -0
  25. {celq-0.3.2 → celq-0.3.3}/src/json2cel_test.rs +0 -0
  26. {celq-0.3.2 → celq-0.3.3}/src/main.rs +0 -0
  27. {celq-0.3.2 → celq-0.3.3}/src/slice_extension.rs +0 -0
  28. {celq-0.3.2 → celq-0.3.3}/src/ungron.rs +0 -0
  29. {celq-0.3.2 → celq-0.3.3}/src/ungron_test.rs +0 -0
@@ -1,13 +1,25 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ [v0.3.3](https://github.com/IvanIsCoding/celq/releases/tag/v0.3.1) - 2026-02-05
5
+ ------------------------------------------------------------------------
6
+
7
+
8
+ ### Added
9
+
10
+ * Added XML support via the `--from-xml` flag.
11
+
4
12
  [v0.3.2](https://github.com/IvanIsCoding/celq/releases/tag/v0.3.2) - 2026-01-31
13
+ ------------------------------------------------------------------------
14
+
5
15
 
6
16
  ### Miscellaneous
7
17
 
8
18
  * Downgraded the MSRV to Rust 1.90
9
19
 
10
20
  [v0.3.1](https://github.com/IvanIsCoding/celq/releases/tag/v0.3.1) - 2026-01-27
21
+ ------------------------------------------------------------------------
22
+
11
23
 
12
24
  ### Added
13
25
 
@@ -201,7 +201,7 @@ dependencies = [
201
201
 
202
202
  [[package]]
203
203
  name = "celq"
204
- version = "0.3.2"
204
+ version = "0.3.3"
205
205
  dependencies = [
206
206
  "anyhow",
207
207
  "cel",
@@ -216,6 +216,7 @@ dependencies = [
216
216
  "serde_json",
217
217
  "tempfile",
218
218
  "toml",
219
+ "xml2json-rs",
219
220
  ]
220
221
 
221
222
  [[package]]
@@ -583,6 +584,15 @@ dependencies = [
583
584
  "unicode-ident",
584
585
  ]
585
586
 
587
+ [[package]]
588
+ name = "quick-xml"
589
+ version = "0.23.1"
590
+ source = "registry+https://github.com/rust-lang/crates.io-index"
591
+ checksum = "11bafc859c6815fbaffbbbf4229ecb767ac913fecb27f9ad4343662e9ef099ea"
592
+ dependencies = [
593
+ "memchr",
594
+ ]
595
+
586
596
  [[package]]
587
597
  name = "quote"
588
598
  version = "1.0.42"
@@ -1143,6 +1153,19 @@ version = "0.46.0"
1143
1153
  source = "registry+https://github.com/rust-lang/crates.io-index"
1144
1154
  checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
1145
1155
 
1156
+ [[package]]
1157
+ name = "xml2json-rs"
1158
+ version = "1.0.1"
1159
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1160
+ checksum = "c6ba4fb1256176d2eb02e25065efade8e43215a4d0743cb823991aea314077ea"
1161
+ dependencies = [
1162
+ "lazy_static",
1163
+ "quick-xml",
1164
+ "regex",
1165
+ "serde",
1166
+ "serde_json",
1167
+ ]
1168
+
1146
1169
  [[package]]
1147
1170
  name = "zerocopy"
1148
1171
  version = "0.8.33"
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "celq"
3
3
  description = "A CEL command-line query tool for JSON data"
4
- version = "0.3.2"
4
+ version = "0.3.3"
5
5
  edition = "2024"
6
6
  rust-version = "1.90"
7
7
  authors = ["Ivan Carvalho <ivancarvalho@gatech.edu>"]
@@ -34,9 +34,10 @@ name = "celq"
34
34
  path = "src/documentation.rs"
35
35
 
36
36
  [features]
37
- default = ["mimalloc", "from-toml", "from-yaml", "greppable"]
37
+ default = ["mimalloc", "from-toml", "from-yaml", "greppable", "from-xml"]
38
38
  from-toml = ["dep:toml"]
39
39
  from-yaml = ["dep:serde-saphyr"]
40
+ from-xml = ["dep:xml2json-rs"]
40
41
  greppable = ["dep:ressa", "dep:resast"]
41
42
 
42
43
  [dependencies]
@@ -52,6 +53,7 @@ toml = { version = "=0.9.8", default-features = false, features = ["parse", "ser
52
53
  serde-saphyr = { version = "=0.0.16", default-features = false, optional = true }
53
54
  ressa = { version = "=0.8.2", optional = true}
54
55
  resast = { version = "=0.5.0", optional = true }
56
+ xml2json-rs = {version = "=1.0.1", optional = true }
55
57
 
56
58
  [dev-dependencies]
57
59
  tempfile = "3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: celq
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Classifier: Intended Audience :: Developers
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
@@ -40,7 +40,7 @@ celq -n --arg='fruit:string=apple' 'fruit.contains("a")'
40
40
  # Outputs: true
41
41
  ```
42
42
 
43
- Popular configuration formats such as JSON5, YAML, and TOML are supported. The closely related format NDJSON is also supported.
43
+ Popular configuration formats such as JSON5, YAML, TOML, and XML are supported. The closely related format NDJSON is also supported.
44
44
 
45
45
  For detailed usage examples and recipes, see the [manual](https://docs.rs/celq/latest/celq/).
46
46
 
@@ -101,6 +101,14 @@ If you are a [Chocolatey](https://community.chocolatey.org/) user on Windows, yo
101
101
  choco install celq
102
102
  ```
103
103
 
104
+ ### WinGet (Windows)
105
+
106
+ If you are a [WinGet](https://learn.microsoft.com/windows/package-manager/winget/) user on Windows, you can install `celq` with:
107
+
108
+ ```bash
109
+ winget install IvanIsCoding.celq
110
+ ```
111
+
104
112
  ### Cargo
105
113
 
106
114
  #### Installing From Source
@@ -179,7 +187,11 @@ su root -c 'install -m 755 celq /usr/local/bin/'
179
187
 
180
188
  ### OpenBSD
181
189
 
182
- OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for instructions.
190
+ OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for installation instructions.
191
+
192
+ ### NetBSD
193
+
194
+ NetBSD builds are tested in CI against the latest stable release. `celq` aims to remain compatible with the Rust version provided by the NetBSD pkgsrc quarterly branch. See the [Cargo](#cargo) section for installation instructions.
183
195
 
184
196
  ### NPM (Node.js/JavaScript)
185
197
 
@@ -208,6 +220,35 @@ If you have [uv](https://github.com/astral-sh/uv) installed, `celq` can be used
208
220
  uvx celq -n '"Hello World"'
209
221
  ```
210
222
 
223
+ ### Conda Forge
224
+
225
+ celq is available on [conda-forge](https://anaconda.org/channels/conda-forge/packages/celq/overview) and can be installed with `conda`, `mamba`, `micromamba`, and `pixi`:
226
+
227
+ ```bash
228
+ conda install -c conda-forge celq
229
+ ```
230
+
231
+ If you have [pixi](https://pixi.prefix.dev/latest/), you can run celq in a temporary environment with:
232
+
233
+ ```bash
234
+ pixi exec celq -n '"Hello World"'
235
+ ```
236
+
237
+ ### Mise
238
+
239
+ celq can be used with [mise](https://mise.jdx.dev/). To install celq, use the Conda back-end:
240
+
241
+ ```bash
242
+ mise use -g conda:celq
243
+ ```
244
+
245
+ Alternatively, add this to `mise.toml`:
246
+
247
+ ```toml
248
+ [tools]
249
+ "conda:celq" = "latest"
250
+ ```
251
+
211
252
  ## Limitations
212
253
 
213
254
  ### Eager JSON Parsing
@@ -19,7 +19,7 @@ celq -n --arg='fruit:string=apple' 'fruit.contains("a")'
19
19
  # Outputs: true
20
20
  ```
21
21
 
22
- Popular configuration formats such as JSON5, YAML, and TOML are supported. The closely related format NDJSON is also supported.
22
+ Popular configuration formats such as JSON5, YAML, TOML, and XML are supported. The closely related format NDJSON is also supported.
23
23
 
24
24
  For detailed usage examples and recipes, see the [manual](https://docs.rs/celq/latest/celq/).
25
25
 
@@ -80,6 +80,14 @@ If you are a [Chocolatey](https://community.chocolatey.org/) user on Windows, yo
80
80
  choco install celq
81
81
  ```
82
82
 
83
+ ### WinGet (Windows)
84
+
85
+ If you are a [WinGet](https://learn.microsoft.com/windows/package-manager/winget/) user on Windows, you can install `celq` with:
86
+
87
+ ```bash
88
+ winget install IvanIsCoding.celq
89
+ ```
90
+
83
91
  ### Cargo
84
92
 
85
93
  #### Installing From Source
@@ -158,7 +166,11 @@ su root -c 'install -m 755 celq /usr/local/bin/'
158
166
 
159
167
  ### OpenBSD
160
168
 
161
- OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for instructions.
169
+ OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for installation instructions.
170
+
171
+ ### NetBSD
172
+
173
+ NetBSD builds are tested in CI against the latest stable release. `celq` aims to remain compatible with the Rust version provided by the NetBSD pkgsrc quarterly branch. See the [Cargo](#cargo) section for installation instructions.
162
174
 
163
175
  ### NPM (Node.js/JavaScript)
164
176
 
@@ -187,6 +199,35 @@ If you have [uv](https://github.com/astral-sh/uv) installed, `celq` can be used
187
199
  uvx celq -n '"Hello World"'
188
200
  ```
189
201
 
202
+ ### Conda Forge
203
+
204
+ celq is available on [conda-forge](https://anaconda.org/channels/conda-forge/packages/celq/overview) and can be installed with `conda`, `mamba`, `micromamba`, and `pixi`:
205
+
206
+ ```bash
207
+ conda install -c conda-forge celq
208
+ ```
209
+
210
+ If you have [pixi](https://pixi.prefix.dev/latest/), you can run celq in a temporary environment with:
211
+
212
+ ```bash
213
+ pixi exec celq -n '"Hello World"'
214
+ ```
215
+
216
+ ### Mise
217
+
218
+ celq can be used with [mise](https://mise.jdx.dev/). To install celq, use the Conda back-end:
219
+
220
+ ```bash
221
+ mise use -g conda:celq
222
+ ```
223
+
224
+ Alternatively, add this to `mise.toml`:
225
+
226
+ ```toml
227
+ [tools]
228
+ "conda:celq" = "latest"
229
+ ```
230
+
190
231
  ## Limitations
191
232
 
192
233
  ### Eager JSON Parsing
@@ -68,6 +68,14 @@ If you are a [Chocolatey](https://community.chocolatey.org/) user on Windows, yo
68
68
  choco install celq
69
69
  ```
70
70
 
71
+ ### WinGet (Windows)
72
+
73
+ If you are a [WinGet](https://learn.microsoft.com/windows/package-manager/winget/) user on Windows, you can install `celq` with:
74
+
75
+ ```bash
76
+ winget install IvanIsCoding.celq
77
+ ```
78
+
71
79
  ### Cargo
72
80
 
73
81
  #### Installing From Source
@@ -168,7 +176,11 @@ su root -c 'install -m 755 celq /usr/local/bin/'
168
176
 
169
177
  ### OpenBSD
170
178
 
171
- OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for instructions.
179
+ OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for installation instructions.
180
+
181
+ ### NetBSD
182
+
183
+ NetBSD builds are tested in CI against the latest stable release. `celq` aims to remain compatible with the Rust version provided by the NetBSD pkgsrc quarterly branch. See the [Cargo](#cargo) section for installation instructions.
172
184
 
173
185
  ### NPM (Node.js/JavaScript)
174
186
 
@@ -197,6 +209,35 @@ If you have [uv](https://github.com/astral-sh/uv) installed, `celq` can be used
197
209
  uvx celq -n '"Hello World"'
198
210
  ```
199
211
 
212
+ ### Conda Forge
213
+
214
+ celq is available on [conda-forge](https://anaconda.org/channels/conda-forge/packages/celq/overview) and can be installed with `conda`, `mamba`, `micromamba`, and `pixi`:
215
+
216
+ ```bash
217
+ conda install -c conda-forge celq
218
+ ```
219
+
220
+ If you have [pixi](https://pixi.prefix.dev/latest/), you can run celq in a temporary environment with:
221
+
222
+ ```bash
223
+ pixi exec celq -n '"Hello World"'
224
+ ```
225
+
226
+ ### Mise
227
+
228
+ celq can be used with [mise](https://mise.jdx.dev/). To install celq, use the Conda back-end:
229
+
230
+ ```bash
231
+ mise use -g conda:celq
232
+ ```
233
+
234
+ Alternatively, add this to `mise.toml`:
235
+
236
+ ```toml
237
+ [tools]
238
+ "conda:celq" = "latest"
239
+ ```
240
+
200
241
  ## Integrity and Authenticity
201
242
 
202
243
  `celq` publishes a `SHA256SUMS` file for each of its release in the [GitHub Releases page](https://github.com/IvanIsCoding/celq/releases). The checksum can be used to verify integrity of the downloaded files.
@@ -39,10 +39,10 @@ See the [installation guide](`crate::installation_guide`) for installation instr
39
39
  ```none
40
40
  A CEL command-line query tool for JSON data
41
41
 
42
- Usage: celq [OPTIONS] <expr|--from-file <FILE>>
42
+ Usage: celq [OPTIONS] [expr]
43
43
 
44
44
  Arguments:
45
- [expr] CEL expression to evaluate
45
+ [expr] CEL expression to evaluate [default: this]
46
46
 
47
47
  Options:
48
48
  -a, --arg <name:type=value> Define argument variables, types, and values. Format: name:type=value. Supported types: int, uint, float, bool, string
@@ -53,6 +53,7 @@ Options:
53
53
  --from-json5 Parse input as JSON5 instead of JSON
54
54
  --from-toml Parse input as TOML instead of JSON
55
55
  --from-yaml Parse input as YAML instead of JSON
56
+ --from-xml Parse input as XML instead of JSON
56
57
  --from-gron Parse input as gron (greppable output) instead of JSON
57
58
  -j, --jobs <N> Parallelism level for NDJSON inputs (number of threads, -1 for all available) [default: 1]
58
59
  -R, --root-var <ROOT_VAR> Variable name for the root JSON input [default: this]
@@ -144,8 +145,8 @@ This file contains the simplified response from the Yahoo Finance Unofficial JSO
144
145
  * [this keyword](#this-keyword)
145
146
  * [Writing Files](#writing-files)
146
147
  * [Output JSON](#output-json)
147
- * [Slicing lists](#slicing-lists)
148
148
  * [Reading CEL from a file](#reading-cel-from-a-file)
149
+ * [Slicing lists](#slicing-lists)
149
150
  * [Dealing with NDJSON](#dealing-with-ndjson)
150
151
  * [Slurping](#slurping)
151
152
  * [Logical Calculator](#logical-calculator)
@@ -156,6 +157,7 @@ This file contains the simplified response from the Yahoo Finance Unofficial JSO
156
157
  * [TOML Support](#toml-support)
157
158
  * [YAML Support](#yaml-support)
158
159
  * [YAML with multiple documents](#yaml-with-multiple-documents)
160
+ * [XML Support](#xml-support)
159
161
  * [Pretty Printing](#pretty-printing)
160
162
  * [Raw Output](#raw-output)
161
163
  * [Grep friendly output](#grep-friendly-output)
@@ -444,6 +446,59 @@ The document gets parsed as a list of documents. To access the `tags` field of t
444
446
  celq --from-yaml 'this[1].tags' < multi.yaml
445
447
  ```
446
448
 
449
+ ### XML Support
450
+
451
+ `celq` supports XML via the `--froml-xml` flag. Take `example.xml`:
452
+
453
+ <details>
454
+ <summary>example.xml</summary>
455
+
456
+ ```xml
457
+ <?xml version="1.0"?>
458
+ <items>
459
+ <item id="1">
460
+ <name>apple</name>
461
+ <price>1.25</price>
462
+ </item>
463
+ <item id="2">
464
+ <name>banana</name>
465
+ <price>0.75</price>
466
+ </item>
467
+ </items>
468
+ ```
469
+ </details>
470
+
471
+ Running `celq --from-xml -S < example.xml` converts it to the following:
472
+
473
+ <details>
474
+ <summary>example_xml.json</summary>
475
+
476
+ ```json
477
+ {
478
+ "items": {
479
+ "item": [
480
+ {
481
+ "$": {
482
+ "id": "1"
483
+ },
484
+ "name": "apple",
485
+ "price": "1.25"
486
+ },
487
+ {
488
+ "$": {
489
+ "id": "2"
490
+ },
491
+ "name": "banana",
492
+ "price": "0.75"
493
+ }
494
+ ]
495
+ }
496
+ }
497
+ ```
498
+ </details>
499
+
500
+ `celq`'s XML parser does not try to convert types and puts attributes in the `$` field.
501
+
447
502
  ### Pretty Printing
448
503
 
449
504
  `celq` by default uses a compact output. This is a contrast to `jq` where the compact output is an opt-in with the `-c` flag.
@@ -19,7 +19,7 @@ celq -n --arg='fruit:string=apple' 'fruit.contains("a")'
19
19
  # Outputs: true
20
20
  ```
21
21
 
22
- Popular configuration formats such as JSON5, YAML, and TOML are supported. The closely related format NDJSON is also supported.
22
+ Popular configuration formats such as JSON5, YAML, TOML, and XML are supported. The closely related format NDJSON is also supported.
23
23
 
24
24
  For detailed usage examples and recipes, see the [manual](https://docs.rs/celq/latest/celq/).
25
25
 
@@ -80,6 +80,14 @@ If you are a [Chocolatey](https://community.chocolatey.org/) user on Windows, yo
80
80
  choco install celq
81
81
  ```
82
82
 
83
+ ### WinGet (Windows)
84
+
85
+ If you are a [WinGet](https://learn.microsoft.com/windows/package-manager/winget/) user on Windows, you can install `celq` with:
86
+
87
+ ```bash
88
+ winget install IvanIsCoding.celq
89
+ ```
90
+
83
91
  ### Cargo
84
92
 
85
93
  #### Installing From Source
@@ -158,7 +166,11 @@ su root -c 'install -m 755 celq /usr/local/bin/'
158
166
 
159
167
  ### OpenBSD
160
168
 
161
- OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for instructions.
169
+ OpenBSD builds are tested in CI using the latest stable release. `celq` strives to always compile with the Rust version provided in the ports tree. Refer to the [Cargo](#cargo) section for installation instructions.
170
+
171
+ ### NetBSD
172
+
173
+ NetBSD builds are tested in CI against the latest stable release. `celq` aims to remain compatible with the Rust version provided by the NetBSD pkgsrc quarterly branch. See the [Cargo](#cargo) section for installation instructions.
162
174
 
163
175
  ### NPM (Node.js/JavaScript)
164
176
 
@@ -187,6 +199,35 @@ If you have [uv](https://github.com/astral-sh/uv) installed, `celq` can be used
187
199
  uvx celq -n '"Hello World"'
188
200
  ```
189
201
 
202
+ ### Conda Forge
203
+
204
+ celq is available on [conda-forge](https://anaconda.org/channels/conda-forge/packages/celq/overview) and can be installed with `conda`, `mamba`, `micromamba`, and `pixi`:
205
+
206
+ ```bash
207
+ conda install -c conda-forge celq
208
+ ```
209
+
210
+ If you have [pixi](https://pixi.prefix.dev/latest/), you can run celq in a temporary environment with:
211
+
212
+ ```bash
213
+ pixi exec celq -n '"Hello World"'
214
+ ```
215
+
216
+ ### Mise
217
+
218
+ celq can be used with [mise](https://mise.jdx.dev/). To install celq, use the Conda back-end:
219
+
220
+ ```bash
221
+ mise use -g conda:celq
222
+ ```
223
+
224
+ Alternatively, add this to `mise.toml`:
225
+
226
+ ```toml
227
+ [tools]
228
+ "conda:celq" = "latest"
229
+ ```
230
+
190
231
  ## Limitations
191
232
 
192
233
  ### Eager JSON Parsing
@@ -24,6 +24,7 @@ pub enum InputFormat {
24
24
  Json5,
25
25
  Toml,
26
26
  Yaml,
27
+ Xml,
27
28
  Gron,
28
29
  }
29
30
 
@@ -129,6 +130,10 @@ pub struct Cli {
129
130
  #[arg(long = "from-yaml")]
130
131
  pub from_yaml: bool,
131
132
 
133
+ /// Parse input as XML instead of JSON
134
+ #[arg(long = "from-xml")]
135
+ pub from_xml: bool,
136
+
132
137
  /// Parse input as gron (greppable output) instead of JSON
133
138
  #[arg(long = "from-gron")]
134
139
  pub from_gron: bool,
@@ -184,6 +189,8 @@ impl Cli {
184
189
  InputFormat::Yaml
185
190
  } else if self.from_toml {
186
191
  InputFormat::Toml
192
+ } else if self.from_xml {
193
+ InputFormat::Xml
187
194
  } else if self.from_json5 {
188
195
  InputFormat::Json5
189
196
  } else if self.slurp {
@@ -62,6 +62,23 @@ pub fn json_to_cel_variables(
62
62
  ));
63
63
  }
64
64
  }
65
+ InputFormat::Xml => {
66
+ #[cfg(feature = "from-xml")]
67
+ {
68
+ xml2json_rs::JsonConfig::new()
69
+ .explicit_array(false)
70
+ .finalize()
71
+ .build_from_xml(json_str)
72
+ .map_err(serde_json::Error::custom)?
73
+ }
74
+
75
+ #[cfg(not(feature = "from-xml"))]
76
+ {
77
+ return Err(serde_json::Error::custom(
78
+ "Binary was compiled without XML support",
79
+ ));
80
+ }
81
+ }
65
82
  InputFormat::Gron => {
66
83
  #[cfg(feature = "greppable")]
67
84
  {
@@ -951,3 +951,106 @@ fn test_slice_fails_without_extensions() -> io::Result<()> {
951
951
 
952
952
  Ok(())
953
953
  }
954
+
955
+ // XML tests
956
+
957
+ // XML with nested elements
958
+ #[cfg(feature = "from-xml")]
959
+ test!(
960
+ xml_nested_elements,
961
+ &[
962
+ "--from-xml",
963
+ "this.database.host + ':' + string(this.database.port)"
964
+ ],
965
+ r#"<database>
966
+ <host>localhost</host>
967
+ <port>5432</port>
968
+ </database>"#,
969
+ "\"localhost:5432\""
970
+ );
971
+
972
+ #[cfg(feature = "from-xml")]
973
+ test!(
974
+ xml_array_of_elements,
975
+ &["--from-xml", "this.servers.server.map(s, s.ip)"],
976
+ r#"<servers>
977
+ <server>
978
+ <ip>192.168.1.1</ip>
979
+ <name>alpha</name>
980
+ </server>
981
+ <server>
982
+ <ip>192.168.1.2</ip>
983
+ <name>beta</name>
984
+ </server>
985
+ </servers>"#,
986
+ "[\"192.168.1.1\",\"192.168.1.2\"]"
987
+ );
988
+
989
+ #[cfg(feature = "from-xml")]
990
+ test!(
991
+ xml_with_attributes,
992
+ &[
993
+ "--from-xml",
994
+ "this.user.name + ' <' + this.user.email + '>'"
995
+ ],
996
+ r#"<user>
997
+ <name>Alice</name>
998
+ <email>alice@example.com</email>
999
+ </user>"#,
1000
+ "\"Alice <alice@example.com>\""
1001
+ );
1002
+
1003
+ #[cfg(feature = "from-xml")]
1004
+ test!(
1005
+ xml_simple_structure,
1006
+ &["--from-xml", "int(this.point.x) + int(this.point.y)"],
1007
+ r#"<point>
1008
+ <x>10</x>
1009
+ <y>20</y>
1010
+ </point>"#,
1011
+ "30"
1012
+ );
1013
+
1014
+ #[cfg(feature = "from-xml")]
1015
+ test!(
1016
+ xml_text_content,
1017
+ &["--from-xml", "this.message"],
1018
+ r#"<message>Hello, World!</message>"#,
1019
+ r#""Hello, World!""#
1020
+ );
1021
+
1022
+ #[cfg(feature = "from-xml")]
1023
+ test!(
1024
+ xml_mixed_content,
1025
+ &[
1026
+ "--from-xml",
1027
+ "this.person.name + ' is ' + string(this.person.age)"
1028
+ ],
1029
+ r#"<person>
1030
+ <name>Bob</name>
1031
+ <age>25</age>
1032
+ </person>"#,
1033
+ "\"Bob is 25\""
1034
+ );
1035
+
1036
+ #[cfg(feature = "from-xml")]
1037
+ test!(
1038
+ xml_to_pretty_sorted_json,
1039
+ &["--from-xml", "--sort-keys", "--pretty-print", "this"],
1040
+ r#"<root>
1041
+ <person>
1042
+ <name>Alice</name>
1043
+ <age>30</age>
1044
+ </person>
1045
+ <id>1</id>
1046
+ </root>"#,
1047
+ r#"{
1048
+ "root": {
1049
+ "id": "1",
1050
+ "person": {
1051
+ "age": "30",
1052
+ "name": "Alice"
1053
+ }
1054
+ }
1055
+ }"#
1056
+ );
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes