Skip to content

Commit

Permalink
Merge pull request #128 from kklingenberg/feature/env-filter
Browse files Browse the repository at this point in the history
Add env filter
  • Loading branch information
01mf02 authored Jan 9, 2024
2 parents 6c20c4e + 362b0e4 commit c17db55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion jaq-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,16 @@ fn now() -> Result<f64, Error> {
}

#[cfg(feature = "std")]
const STD: &[(&str, usize, RunPtr)] = &[("now", 0, |_, _| box_once(now().map(Val::Float)))];
const STD: &[(&str, usize, RunPtr)] = &[
("env", 0, |_, _| {
box_once(Ok(Val::obj(
std::env::vars()
.map(|(k, v)| (Rc::new(k), Val::str(v)))
.collect(),
)))
}),
("now", 0, |_, _| box_once(now().map(Val::Float))),
];

#[cfg(feature = "parse_json")]
/// Convert string to a single JSON value.
Expand Down
8 changes: 8 additions & 0 deletions jaq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ fn binds(cli: &Cli) -> Result<Vec<(String, Val)>, Error> {
})?;

var_val.push(("ARGS".to_string(), args_named(&var_val)));
var_val.push((
"ENV".to_string(),
Val::obj(
std::env::vars()
.map(|(k, v)| (k.into(), Val::str(v)))
.collect(),
),
));

Ok(var_val)
}
Expand Down

0 comments on commit c17db55

Please sign in to comment.