git.delta.rocks / jrsonnet / refs/commits / 7e00c7d820e8

difftreelog

Merge pull request #17 from CertainLach/cli-stdin-input

Yaroslav Bulyukin2020-10-20parents: #8a2b974 #dcb0efa.patch.diff
in: master
Read code from stdin

1 file changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
4use jrsonnet_evaluator::{error::LocError, EvaluationState, ManifestFormat};4use jrsonnet_evaluator::{error::LocError, EvaluationState, ManifestFormat};
5use std::{5use std::{
6 fs::{create_dir_all, File},6 fs::{create_dir_all, File},
7 io::Read,
7 io::Write,8 io::Write,
8 path::PathBuf,9 path::PathBuf,
9 rc::Rc,10 rc::Rc,
61 Evaluation(jrsonnet_evaluator::error::LocError),62 Evaluation(jrsonnet_evaluator::error::LocError),
62 #[error("io error")]63 #[error("io error")]
63 Io(#[from] std::io::Error),64 Io(#[from] std::io::Error),
65 #[error("input is not utf8 encoded")]
66 Utf8(#[from] std::str::Utf8Error),
64}67}
65impl From<LocError> for Error {68impl From<LocError> for Error {
66 fn from(e: LocError) -> Self {69 fn from(e: LocError) -> Self {
89 Rc::new(PathBuf::from("args")),92 Rc::new(PathBuf::from("args")),
90 (&opts.input.input as &str).into(),93 (&opts.input.input as &str).into(),
91 )?94 )?
92 } else {95 } else if opts.input.input == "-" {
96 let mut input = Vec::new();
97 std::io::stdin().read_to_end(&mut input)?;
98 let input_str = std::str::from_utf8(&input)?.into();
99 state.evaluate_snippet_raw(Rc::new(PathBuf::from("<stdin>")), input_str)?
100 } else {
93 state.evaluate_file_raw(&PathBuf::from(opts.input.input))?101 state.evaluate_file_raw(&PathBuf::from(opts.input.input))?
94 };102 };
95103