git.delta.rocks / jrsonnet / refs/commits / fe52b32db444

difftreelog

source

crates/jrsonnet-cli/src/trace.rs1.2 KiBsourcehistory
1use clap::{Parser, ValueEnum};2use jrsonnet_evaluator::{3	error::Result,4	trace::{CompactFormat, ExplainingFormat, PathResolver},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 = ();31	fn configure(&self, s: &State) -> Result<()> {32		let resolver = PathResolver::new_cwd_fallback();33		match self34			.trace_format35			.as_ref()36			.unwrap_or(&TraceFormatName::Compact)37		{38			TraceFormatName::Compact => s.set_trace_format(CompactFormat {39				resolver,40				padding: 4,41			}),42			TraceFormatName::Explaining => s.set_trace_format(ExplainingFormat { resolver }),43		}44		s.set_max_trace(self.max_trace);45		Ok(())46	}47}