difftreelog
Enable multi-occurences for --jpath + improve positional params error message
in: master
2 files changed
crates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth1mod 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)]20#[clap(help_heading = "INPUT")]21pub struct InputOpts {22 #[clap(23 long,24 short = 'e',25 about = "Treat input as code, evaluate them instead of reading file"26 )]27 pub exec: bool,2829 #[clap(30 about = "Path to the file to be compiled if `--evaluate` is unset, otherwise code itself"31 )]32 pub input: String,33}3435#[derive(Clap)]36#[clap(help_heading = "OPTIONS")]37pub struct MiscOpts {38 /// Disable standard library.39 /// By default standard library will be available via global `std` variable.40 /// Note that standard library will still be loaded41 /// if chosen manifestification method is not `none`.42 #[clap(long)]43 no_stdlib: bool,4445 /// Maximal allowed number of stack frames,46 /// stack overflow error will be raised if this number gets exceeded.47 #[clap(long, short = 's', default_value = "200")]48 max_stack: usize,4950 /// Library search dirs.51 /// Any not found `imported` file will be searched in these.52 /// This can also be specified via `JSONNET_PATH` variable,53 /// which should contain a colon-separated (semicolon-separated on Windows) list of directories.54 #[clap(long, short = 'J')]55 jpath: Vec<PathBuf>,56}57impl ConfigureState for MiscOpts {58 fn configure(&self, state: &EvaluationState) -> Result<()> {59 if !self.no_stdlib {60 state.with_stdlib();61 }6263 state.set_import_resolver(Box::new(FileImportResolver {64 library_paths: self.jpath.clone(),65 }));6667 state.set_max_stack(self.max_stack);68 Ok(())69 }70}7172/// General configuration of jsonnet73#[derive(Clap)]74#[clap(name = "jrsonnet", version, author)]75pub struct GeneralOpts {76 #[clap(flatten)]77 misc: MiscOpts,7879 #[clap(flatten)]80 tla: TLAOpts,81 #[clap(flatten)]82 ext: ExtVarOpts,8384 #[clap(flatten)]85 trace: TraceOpts,86}8788impl ConfigureState for GeneralOpts {89 fn configure(&self, state: &EvaluationState) -> Result<()> {90 // Configure trace first, because tla-code/ext-code can throw91 self.trace.configure(state)?;92 self.misc.configure(state)?;93 self.tla.configure(state)?;94 self.ext.configure(state)?;95 Ok(())96 }97}9899#[derive(Clap)]100#[clap(help_heading = "GARBAGE COLLECTION")]101pub struct GcOpts {102 /// Min bytes allocated to start garbage collection103 #[clap(long, default_value = "20000000")]104 gc_initial_threshold: usize,105 /// How much heap should grow after unsuccessful garbage collection106 #[clap(long)]107 gc_used_space_ratio: Option<f64>,108 /// Do not skip gc on exit109 #[clap(long)]110 gc_collect_on_exit: bool,111 /// Print gc stats before exit112 #[clap(long)]113 gc_print_stats: bool,114 /// Force garbage collection before printing stats115 /// Useful for checking for memory leaks116 /// Does nothing useless --gc-print-stats is specified117 #[clap(long)]118 gc_collect_before_printing_stats: bool,119}120impl GcOpts {121 pub fn stats_printer(&self) -> Option<GcStatsPrinter> {122 self.gc_print_stats123 .then(|| GcStatsPrinter(self.gc_collect_before_printing_stats))124 }125 pub fn configure_global(&self) {126 jrsonnet_gc::configure(|config| {127 config.leak_on_drop = !self.gc_collect_on_exit;128 config.threshold = self.gc_initial_threshold;129 if let Some(used_space_ratio) = self.gc_used_space_ratio {130 config.used_space_ratio = used_space_ratio;131 }132 });133 }134}135pub struct GcStatsPrinter(bool);136impl Drop for GcStatsPrinter {137 fn drop(&mut self) {138 if self.0 {139 jrsonnet_gc::force_collect()140 }141 eprintln!("=== GC STATS ===");142 jrsonnet_gc::configure(|c| {143 eprintln!("Final threshold: {:?}", c.threshold);144 });145 let stats = jrsonnet_gc::stats();146 eprintln!("Collections performed: {}", stats.collections_performed);147 eprintln!("Bytes still allocated: {}", stats.bytes_allocated);148 }149}crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -62,7 +62,7 @@
let mut defaults_started = false;
for param in ¶ms {
defaults_started = defaults_started || param.1.is_some();
- assert_eq!(defaults_started, param.1.is_some(), "defauld parameters should be used after all positionals");
+ assert_eq!(defaults_started, param.1.is_some(), "defauld parameters should be used after all positionals. Misplaced default parameter: {:?}", param.0);
}
expr::ParamsDesc(Rc::new(params))
}