Skip to content

Commit c17db55

Browse files
authored
Merge pull request #128 from kklingenberg/feature/env-filter
Add env filter
2 parents 6c20c4e + 362b0e4 commit c17db55

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

jaq-core/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,16 @@ fn now() -> Result<f64, Error> {
360360
}
361361

362362
#[cfg(feature = "std")]
363-
const STD: &[(&str, usize, RunPtr)] = &[("now", 0, |_, _| box_once(now().map(Val::Float)))];
363+
const STD: &[(&str, usize, RunPtr)] = &[
364+
("env", 0, |_, _| {
365+
box_once(Ok(Val::obj(
366+
std::env::vars()
367+
.map(|(k, v)| (Rc::new(k), Val::str(v)))
368+
.collect(),
369+
)))
370+
}),
371+
("now", 0, |_, _| box_once(now().map(Val::Float))),
372+
];
364373

365374
#[cfg(feature = "parse_json")]
366375
/// Convert string to a single JSON value.

jaq/src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ fn binds(cli: &Cli) -> Result<Vec<(String, Val)>, Error> {
218218
})?;
219219

220220
var_val.push(("ARGS".to_string(), args_named(&var_val)));
221+
var_val.push((
222+
"ENV".to_string(),
223+
Val::obj(
224+
std::env::vars()
225+
.map(|(k, v)| (k.into(), Val::str(v)))
226+
.collect(),
227+
),
228+
));
221229

222230
Ok(var_val)
223231
}

0 commit comments

Comments
 (0)