git.delta.rocks / jrsonnet / refs/commits / dcb0efaafd9f

difftreelog

feat read code from stdin

Yaroslav Bolyukin2020-10-19parent: #e99c281.patch.diff
in: master
Fixes #9

1 file changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
3use jrsonnet_evaluator::{error::LocError, EvaluationState};3use jrsonnet_evaluator::{error::LocError, EvaluationState};
4use std::{4use std::{
5 fs::{create_dir_all, File},5 fs::{create_dir_all, File},
6 io::Read,
6 io::Write,7 io::Write,
7 path::PathBuf,8 path::PathBuf,
8 rc::Rc,9 rc::Rc,
56 Evaluation(jrsonnet_evaluator::error::LocError),57 Evaluation(jrsonnet_evaluator::error::LocError),
57 #[error("io error")]58 #[error("io error")]
58 Io(#[from] std::io::Error),59 Io(#[from] std::io::Error),
60 #[error("input is not utf8 encoded")]
61 Utf8(#[from] std::str::Utf8Error),
59}62}
60impl From<LocError> for Error {63impl From<LocError> for Error {
61 fn from(e: LocError) -> Self {64 fn from(e: LocError) -> Self {
83 Rc::new(PathBuf::from("args")),86 Rc::new(PathBuf::from("args")),
84 (&opts.input.input as &str).into(),87 (&opts.input.input as &str).into(),
85 )?88 )?
86 } else {89 } else if opts.input.input == "-" {
90 let mut input = Vec::new();
91 std::io::stdin().read_to_end(&mut input)?;
92 let input_str = std::str::from_utf8(&input)?.into();
93 state.evaluate_snippet_raw(Rc::new(PathBuf::from("<stdin>")), input_str)?
94 } else {
87 state.evaluate_file_raw(&PathBuf::from(opts.input.input))?95 state.evaluate_file_raw(&PathBuf::from(opts.input.input))?
88 };96 };
8997