From dcb0efaafd9fd791d1fea3678fbc96478bf12922 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 19 Oct 2020 15:30:58 +0000 Subject: [PATCH] feat: read code from stdin Fixes #9 --- --- a/cmds/jrsonnet/src/main.rs +++ b/cmds/jrsonnet/src/main.rs @@ -3,6 +3,7 @@ use jrsonnet_evaluator::{error::LocError, EvaluationState}; use std::{ fs::{create_dir_all, File}, + io::Read, io::Write, path::PathBuf, rc::Rc, @@ -56,6 +57,8 @@ Evaluation(jrsonnet_evaluator::error::LocError), #[error("io error")] Io(#[from] std::io::Error), + #[error("input is not utf8 encoded")] + Utf8(#[from] std::str::Utf8Error), } impl From for Error { fn from(e: LocError) -> Self { @@ -83,6 +86,11 @@ Rc::new(PathBuf::from("args")), (&opts.input.input as &str).into(), )? + } else if opts.input.input == "-" { + let mut input = Vec::new(); + std::io::stdin().read_to_end(&mut input)?; + let input_str = std::str::from_utf8(&input)?.into(); + state.evaluate_snippet_raw(Rc::new(PathBuf::from("")), input_str)? } else { state.evaluate_file_raw(&PathBuf::from(opts.input.input))? }; -- gitstuff