Skip to content

Commit 9f59731

Browse files
committed
Support JSONNET_PATH/J/jpath
1 parent 3057166 commit 9f59731

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Options:
7878
[possible values: sql, jsonnet, json]
7979
--proxy-url <PROXY_URL>
8080
sqlsonnet proxy URL [env: SQLSONNET_PROXY=]
81+
-J, --jpath <JPATH>
82+
Library path [env: JSONNET_PATH=]
8183
-e, --execute
8284
Send query to Clickhouse proxy (--proxy-url) for execution
8385
-h, --help

sqlsonnet-cli/src/sqlsonnet.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::BTreeMap;
22
use std::io::IsTerminal;
3+
use std::path::PathBuf;
34
use std::str::FromStr;
45

56
use clap::Parser;
@@ -53,6 +54,9 @@ struct Flags {
5354
/// Send query to Clickhouse proxy (--proxy-url) for execution
5455
#[clap(long, short, conflicts_with = "from_sql", requires = "proxy_url")]
5556
execute: bool,
57+
/// Library path
58+
#[clap(long, short = 'J', env = "JSONNET_PATH")]
59+
jpath: Option<PathBuf>,
5660
}
5761

5862
#[derive(Clone)]
@@ -191,8 +195,13 @@ async fn main_impl() -> Result<(), Error> {
191195
let contents = sqlsonnet::import_utils() + &input;
192196
info!("Converting Jsonnet file {} to SQL", filename);
193197

198+
let mut resolver = args.input.resolver();
199+
if let Some(jpath) = args.jpath.clone() {
200+
resolver.add(jpath);
201+
}
202+
194203
// TODO: Support passing a single query.
195-
let queries = Queries::from_jsonnet(&contents, args.input.resolver())?;
204+
let queries = Queries::from_jsonnet(&contents, resolver)?;
196205

197206
let has = |l| display_format.iter().any(|l2| l2 == &l);
198207
// Display queries

sqlsonnet/src/jsonnet/resolver.rs

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ impl FsResolver {
4646
.collect(),
4747
)
4848
}
49+
pub fn add(&mut self, path: PathBuf) {
50+
self.search_paths.push(path);
51+
}
4952
pub fn new(search_paths: Vec<PathBuf>) -> Self {
5053
Self { search_paths }
5154
}

0 commit comments

Comments
 (0)