1mod ext;2mod manifest;3mod tla;4mod trace;56pub use ext::*;7pub use manifest::*;8pub use tla::*;9pub use trace::*;1011use clap::Clap;12use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};13use std::path::PathBuf;1415pub trait ConfigureState {16 fn configure(&self, state: &EvaluationState) -> Result<()>;17}1819#[derive(Clap)]2021pub struct InputOpts {22 #[clap(23 long,24 short = 'e',25 about = "Treat input as code, evaluate them instead of reading file"26 )]27 pub evaluate: bool,2829 #[clap(about = "Path to the file to be compiled if `--evaluate` is unset, \30 otherwise code itself")]31 pub input: String,32}3334#[derive(Clap)]3536pub struct MiscOpts {37 38 39 40 41 #[clap(long)]42 no_stdlib: bool,4344 45 46 #[clap(long, short = 's', default_value = "200")]47 max_stack: usize,4849 50 51 52 53 #[clap(long, short = 'J')]54 jpath: Vec<PathBuf>,55}56impl ConfigureState for MiscOpts {57 fn configure(&self, state: &EvaluationState) -> Result<()> {58 if !self.no_stdlib {59 state.with_stdlib();60 }6162 state.set_import_resolver(Box::new(FileImportResolver {63 library_paths: self.jpath.clone(),64 }));6566 state.set_max_stack(self.max_stack);67 Ok(())68 }69}707172#[derive(Clap)]73#[clap(name = "jrsonnet", version, author)]74pub struct GeneralOpts {75 #[clap(flatten)]76 misc: MiscOpts,7778 #[clap(flatten)]79 tla: TLAOpts,80 #[clap(flatten)]81 ext: ExtVarOpts,8283 #[clap(flatten)]84 trace: TraceOpts,85}8687impl ConfigureState for GeneralOpts {88 fn configure(&self, state: &EvaluationState) -> Result<()> {89 90 self.trace.configure(state)?;91 self.misc.configure(state)?;92 self.tla.configure(state)?;93 self.ext.configure(state)?;94 Ok(())95 }96}