Skip to content

Commit f2a8adb

Browse files
committed
Add --from-gron support (pt 1)
1 parent 440ce18 commit f2a8adb

7 files changed

Lines changed: 374 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ path = "src/documentation.rs"
3535
default = ["mimalloc", "from-toml", "from-yaml", "greppable"]
3636
from-toml = ["dep:toml"]
3737
from-yaml = ["dep:serde-saphyr"]
38-
greppable = ["dep:gron"]
38+
greppable = ["dep:gron", "dep:ressa", "dep:resast"]
3939

4040
[dependencies]
4141
anyhow = "1"
@@ -49,6 +49,8 @@ json5 = "0.4"
4949
toml = { version = "=0.9.8", default-features = false, features = ["parse", "serde", "preserve_order"], optional = true }
5050
serde-saphyr = { version = "=0.0.14", default-features = false, optional = true }
5151
gron = { version = "=0.4.0", optional = true }
52+
ressa = { version = "=0.8.2", optional = true}
53+
resast = { version = "=0.5.0", optional = true }
5254

5355
[dev-dependencies]
5456
tempfile = "3"

src/cli.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl std::str::FromStr for Argument {
7272
),
7373
group(
7474
ArgGroup::new("input_format")
75-
.args(&["slurp", "from_json5", "from_toml", "from_yaml"])
75+
.args(&["slurp", "from_json5", "from_toml", "from_yaml", "from_gron"])
7676
),
7777
group(
7878
ArgGroup::new("output_style")
@@ -120,6 +120,10 @@ pub struct Cli {
120120
#[arg(long = "from-yaml")]
121121
pub from_yaml: bool,
122122

123+
/// Parse input as gron (greppable output) instead of JSON
124+
#[arg(long = "from-gron")]
125+
pub from_gron: bool,
126+
123127
/// Parallelism level for NDJSON inputs (number of threads, -1 for all available)
124128
#[arg(
125129
short = 'j',
@@ -180,6 +184,7 @@ pub struct InputParameters {
180184
pub from_json5: bool,
181185
pub from_toml: bool,
182186
pub from_yaml: bool,
187+
pub from_gron: bool,
183188
pub parallelism: i32,
184189
pub sort_keys: bool,
185190
pub pretty_print: bool,

src/input_handler_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn default_params() -> InputParameters {
99
from_json5: false,
1010
from_toml: false,
1111
from_yaml: false,
12+
from_gron: false,
1213
parallelism: -1,
1314
sort_keys: false,
1415
pretty_print: false,

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ pub use cli::InputParameters;
2222
use input_handler::handle_input;
2323
pub use json2cel::json_to_cel_variables;
2424

25+
#[cfg(feature = "greppable")]
26+
mod ungron;
27+
#[cfg(feature = "greppable")]
28+
pub use ungron::gron_to_json;
29+
2530
#[cfg(feature = "mimalloc")]
2631
#[global_allocator]
2732
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
@@ -74,6 +79,7 @@ fn main() -> io::Result<()> {
7479
from_json5: cli.from_json5,
7580
from_toml: cli.from_toml,
7681
from_yaml: cli.from_yaml,
82+
from_gron: cli.from_gron,
7783
parallelism: cli.parallelism,
7884
sort_keys: cli.sort_keys,
7985
pretty_print: cli.pretty_print,

0 commit comments

Comments
 (0)