git.delta.rocks / jrsonnet / refs/commits / 6c1a2fa6d186

difftreelog

docs fix `DebugOpts`

progrm_jarvis2020-08-03parent: #656c8fd.patch.diff
in: master

1 file changed

modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
before · cmds/jrsonnet/src/main.rs
1use clap::Clap;2use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts};3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::{path::PathBuf, rc::Rc};56#[cfg(feature = "mimalloc")]7#[global_allocator]8static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;910#[derive(Clap)]11// #[clap(help_heading = "DEBUG")]12struct DebugOpts {13	/// Required OS stack size, probally you shouldn't change it, unless jrsonnet is failing with stack overflow14	#[clap(long, name = "size")]15	pub os_stack: Option<usize>,16}1718#[derive(Clap)]19struct Opts {20	#[clap(flatten)]21	input: InputOpts,22	#[clap(flatten)]23	general: GeneralOpts,24	#[clap(flatten)]25	manifest: ManifestOpts,26	#[clap(flatten)]27	debug: DebugOpts,28}2930fn main() {31	let opts: Opts = Opts::parse();32	if let Some(size) = opts.debug.os_stack {33		std::thread::Builder::new()34			.stack_size(size * 1024 * 1024)35			.spawn(|| main_catch(opts))36			.expect("new thread spawned")37			.join()38			.expect("thread finished successfully");39	} else {40		main_catch(opts)41	}42}4344fn main_catch(opts: Opts) {45	let state = EvaluationState::default();46	if let Err(e) = main_real(&state, opts) {47		println!("{}", state.stringify_err(&e));48	}49}5051fn main_real(state: &EvaluationState, opts: Opts) -> Result<()> {52	opts.general.configure(&state)?;53	opts.manifest.configure(&state)?;5455	let val = if opts.input.evaluate {56		state.evaluate_snippet_raw(57			Rc::new(PathBuf::from("args")),58			(&opts.input.input as &str).into(),59		)?60	} else {61		state.evaluate_file_raw(&PathBuf::from(opts.input.input))?62	};6364	let val = state.with_tla(val)?;6566	println!("{}", state.manifest(val)?);6768	Ok(())69}
after · cmds/jrsonnet/src/main.rs
1use clap::Clap;2use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts};3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::{path::PathBuf, rc::Rc};56#[cfg(feature = "mimalloc")]7#[global_allocator]8static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;910#[derive(Clap)]11// #[clap(help_heading = "DEBUG")]12struct DebugOpts {13	/// Required OS stack size.14	/// This shouldn't be changed unless jrsonnet is failing with stack overflow error.15	#[clap(long, name = "size")]16	pub os_stack: Option<usize>,17}1819#[derive(Clap)]20struct Opts {21	#[clap(flatten)]22	input: InputOpts,23	#[clap(flatten)]24	general: GeneralOpts,25	#[clap(flatten)]26	manifest: ManifestOpts,27	#[clap(flatten)]28	debug: DebugOpts,29}3031fn main() {32	let opts: Opts = Opts::parse();33	if let Some(size) = opts.debug.os_stack {34		std::thread::Builder::new()35			.stack_size(size * 1024 * 1024)36			.spawn(|| main_catch(opts))37			.expect("new thread spawned")38			.join()39			.expect("thread finished successfully");40	} else {41		main_catch(opts)42	}43}4445fn main_catch(opts: Opts) {46	let state = EvaluationState::default();47	if let Err(e) = main_real(&state, opts) {48		println!("{}", state.stringify_err(&e));49	}50}5152fn main_real(state: &EvaluationState, opts: Opts) -> Result<()> {53	opts.general.configure(&state)?;54	opts.manifest.configure(&state)?;5556	let val = if opts.input.evaluate {57		state.evaluate_snippet_raw(58			Rc::new(PathBuf::from("args")),59			(&opts.input.input as &str).into(),60		)?61	} else {62		state.evaluate_file_raw(&PathBuf::from(opts.input.input))?63	};6465	let val = state.with_tla(val)?;6667	println!("{}", state.manifest(val)?);6869	Ok(())70}