Skip to content

Commit

Permalink
feat(builtins): Implement inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayan-724 committed Dec 14, 2024
1 parent e09679e commit 9257f26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/builtins/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ pub fn import(backtrace: Rc<NixBacktrace>, argument: NixValueWrapped) {
Scope::import_path(backtrace, path)
}

#[builtin]
/// Log a variable and return it
pub fn inspect(backtrace: Rc<NixBacktrace>, argument: NixVar) {
let argument = argument.resolve_set(true, backtrace)?;
println!("{argument:#?}");
Ok(argument)
}

#[builtin]
pub fn is_attrs(argument: NixValueWrapped) {
Ok(NixValue::Bool(argument.borrow().is_attr_set()).wrap())
Expand Down
3 changes: 2 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ impl Scope {
.resolve(backtrace.clone())?;

let has_attr = self
.resolve_attr_path(backtrace, value, node.attrpath().unwrap())?
.resolve_attr_path(backtrace.clone(), value, node.attrpath().unwrap())?
.and_then(|v| v.resolve(backtrace))
.is_ok();

Ok(NixValue::Bool(has_attr).wrap_var())
Expand Down

0 comments on commit 9257f26

Please sign in to comment.