diff options
Diffstat (limited to 'tvix/eval')
-rw-r--r-- | tvix/eval/src/eval.rs | 3 | ||||
-rw-r--r-- | tvix/eval/src/main.rs | 15 |
2 files changed, 16 insertions, 2 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs index 6a35630b3ff7..bfd827e2ca5b 100644 --- a/tvix/eval/src/eval.rs +++ b/tvix/eval/src/eval.rs @@ -36,6 +36,9 @@ pub struct Options { /// A colon-separated list of directories to use to resolve `<...>`-style paths #[cfg_attr(feature = "repl", clap(long, short = 'I', env = "NIX_PATH"))] nix_search_path: Option<NixSearchPath>, + + #[cfg_attr(feature = "repl", clap(long))] + pub raw: bool, } impl Options { diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs index 22bea16d0e20..bef48d07a0c4 100644 --- a/tvix/eval/src/main.rs +++ b/tvix/eval/src/main.rs @@ -2,6 +2,7 @@ use std::{fs, path::PathBuf}; use clap::Parser; use rustyline::{error::ReadlineError, Editor}; +use tvix_eval::Value; #[derive(Parser)] struct Args { @@ -21,8 +22,9 @@ fn main() { if let Some(file) = args.script { run_file(file, args.eval_options) } else if let Some(expr) = args.expr { + let raw = args.eval_options.raw; if let Ok(result) = tvix_eval::interpret(&expr, None, args.eval_options) { - println!("=> {} :: {}", result, result.type_of()) + println_result(&result, raw); } } else { run_prompt(args.eval_options) @@ -34,12 +36,21 @@ fn run_file(mut path: PathBuf, eval_options: tvix_eval::Options) { path.push("default.nix"); } let contents = fs::read_to_string(&path).expect("failed to read the input file"); + let raw = eval_options.raw; match tvix_eval::interpret(&contents, Some(path), eval_options) { - Ok(result) => println!("=> {} :: {}", result, result.type_of()), + Ok(result) => println_result(&result, raw), Err(err) => eprintln!("{}", err), } } +fn println_result(result: &Value, raw: bool) { + if raw { + println!("{}", result.to_str().unwrap().as_str()) + } else { + println!("=> {} :: {}", result, result.type_of()) + } +} + fn state_dir() -> Option<PathBuf> { let mut path = dirs::data_dir(); if let Some(p) = path.as_mut() { |