From 1e852098091dcaaaf3b9750c6dff5e465403f8c3 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 8 Oct 2022 14:22:26 -0400 Subject: [PATCH] feat(tvix/eval): Handle invoking binary with a directory Similar to what we do for import, push on a `default.nix` to the path that the top-level is invoked with (if any) if it's a directory. Change-Id: I281bd44e3c8803b6765c886ae5fd08f549e2e563 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6895 Autosubmit: grfn Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/main.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs index efd4d14c3..0fbc7ad9a 100644 --- a/tvix/eval/src/main.rs +++ b/tvix/eval/src/main.rs @@ -1,7 +1,4 @@ -use std::{ - fs, - path::{Path, PathBuf}, -}; +use std::{fs, path::PathBuf}; use clap::Parser; use rustyline::{error::ReadlineError, Editor}; @@ -18,17 +15,18 @@ struct Args { fn main() { let args = Args::parse(); - if let Some(file) = &args.script { + if let Some(file) = args.script { run_file(file, args.eval_options) } else { run_prompt(args.eval_options) } } -fn run_file(file: &Path, eval_options: tvix_eval::Options) { - let contents = fs::read_to_string(file).expect("failed to read the input file"); - let path = Path::new(file).to_owned(); - +fn run_file(mut path: PathBuf, eval_options: tvix_eval::Options) { + if path.is_dir() { + path.push("default.nix"); + } + let contents = fs::read_to_string(&path).expect("failed to read the input file"); match tvix_eval::interpret(&contents, Some(path), eval_options) { Ok(result) => println!("=> {} :: {}", result, result.type_of()), Err(err) => eprintln!("{}", err),