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:
parent
207f3dd47e
commit
1e85209809
1 changed files with 7 additions and 9 deletions
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue