git.delta.rocks / jrsonnet / refs/commits / 8e60cf17e166

difftreelog

feat read paths from JSONNET_PATH env

Yaroslav Bolyukin2021-11-10parent: #a735ba7.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
1010
11use clap::Clap;11use clap::Clap;
12use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};12use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
13use std::path::PathBuf;13use std::{env, path::PathBuf};
1414
15pub trait ConfigureState {15pub trait ConfigureState {
16 fn configure(&self, state: &EvaluationState) -> Result<()>;16 fn configure(&self, state: &EvaluationState) -> Result<()>;
47 #[clap(long, short = 's', default_value = "200")]47 #[clap(long, short = 's', default_value = "200")]
48 max_stack: usize,48 max_stack: usize,
4949
50 /// Library search dirs.50 /// Library search dirs. (right-most wins)
51 /// Any not found `imported` file will be searched in these.51 /// Any not found `imported` file will be searched in these.
52 /// This can also be specified via `JSONNET_PATH` variable,52 /// This can also be specified via `JSONNET_PATH` variable,
53 /// which should contain a colon-separated (semicolon-separated on Windows) list of directories.53 /// which should contain a colon-separated (semicolon-separated on Windows) list of directories.
60 state.with_stdlib();60 state.with_stdlib();
61 }61 }
62
63 let mut library_paths = self.jpath.clone();
64 library_paths.reverse();
65 if let Some(path) = env::var_os("JSONNET_PATH") {
66 library_paths.extend(env::split_paths(path.as_os_str()));
67 }
6268
63 state.set_import_resolver(Box::new(FileImportResolver {69 state.set_import_resolver(Box::new(FileImportResolver { library_paths }));
64 library_paths: self.jpath.clone(),
65 }));
6670
67 state.set_max_stack(self.max_stack);71 state.set_max_stack(self.max_stack);