git.delta.rocks / jrsonnet / refs/commits / 54c4db58ad3d

difftreelog

source

crates/jrsonnet-cli/src/trace.rs1.3 KiBsourcehistory
1use clap::{Parser, ValueEnum};2use jrsonnet_evaluator::{3	error::Result,4	trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat},5	State,6};78use crate::ConfigureState;910#[derive(PartialEq, Eq, ValueEnum, Clone)]11pub enum TraceFormatName {12	/// Only show `filename:line:column`13	Compact,14	/// Display source code with attached trace annotations15	Explaining,16}1718#[derive(Parser)]19#[clap(next_help_heading = "STACK TRACE VISUAL")]20pub struct TraceOpts {21	/// Format of stack traces' display in console.22	#[clap(long)]23	trace_format: Option<TraceFormatName>,24	/// Amount of stack trace elements to be displayed.25	/// If set to `0` then full stack trace will be displayed.26	#[clap(long, short = 't', default_value = "20")]27	max_trace: usize,28}29impl ConfigureState for TraceOpts {30	type Guards = Box<dyn TraceFormat>;31	fn configure(&self, _s: &State) -> Result<Self::Guards> {32		let resolver = PathResolver::new_cwd_fallback();33		let max_trace = self.max_trace;34		let format: Box<dyn TraceFormat> = match self35			.trace_format36			.as_ref()37			.unwrap_or(&TraceFormatName::Compact)38		{39			TraceFormatName::Compact => Box::new(CompactFormat {40				resolver,41				padding: 4,42				max_trace,43			}),44			TraceFormatName::Explaining => Box::new(ExplainingFormat {45				resolver,46				max_trace,47			}),48		};49		Ok(format)50	}51}