feat(tvix/eval): Allow directly evaluating an expr via main

This *maybe* should do something to check that we don't pass both a file
and an expr, but for now this is useful enough to cut corners (plus
we're probably due for a CLI revamp eventually anyway).

Change-Id: Id44357074150b336b6215ba596cc52d01d037dbd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6941
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2022-10-10 19:41:42 -04:00 committed by grfn
parent 4283f0139a
commit 1181bd78fc

View file

@ -8,6 +8,9 @@ struct Args {
/// Path to a script to evaluate /// Path to a script to evaluate
script: Option<PathBuf>, script: Option<PathBuf>,
#[clap(long, short = 'E')]
expr: Option<String>,
#[clap(flatten)] #[clap(flatten)]
eval_options: tvix_eval::Options, eval_options: tvix_eval::Options,
} }
@ -17,6 +20,10 @@ fn main() {
if let Some(file) = args.script { if let Some(file) = args.script {
run_file(file, args.eval_options) run_file(file, args.eval_options)
} else if let Some(expr) = args.expr {
if let Ok(result) = tvix_eval::interpret(&expr, None, args.eval_options) {
println!("=> {} :: {}", result, result.type_of())
}
} else { } else {
run_prompt(args.eval_options) run_prompt(args.eval_options)
} }