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 <grfn@gws.fyi>
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2022-10-08 14:22:26 -04:00 committed by clbot
parent 207f3dd47e
commit 1e85209809

View file

@ -1,7 +1,4 @@
use std::{ use std::{fs, path::PathBuf};
fs,
path::{Path, PathBuf},
};
use clap::Parser; use clap::Parser;
use rustyline::{error::ReadlineError, Editor}; use rustyline::{error::ReadlineError, Editor};
@ -18,17 +15,18 @@ struct Args {
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
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 { } else {
run_prompt(args.eval_options) run_prompt(args.eval_options)
} }
} }
fn run_file(file: &Path, eval_options: tvix_eval::Options) { fn run_file(mut path: PathBuf, eval_options: tvix_eval::Options) {
let contents = fs::read_to_string(file).expect("failed to read the input file"); if path.is_dir() {
let path = Path::new(file).to_owned(); 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) { match tvix_eval::interpret(&contents, Some(path), eval_options) {
Ok(result) => println!("=> {} :: {}", result, result.type_of()), Ok(result) => println!("=> {} :: {}", result, result.type_of()),
Err(err) => eprintln!("{}", err), Err(err) => eprintln!("{}", err),