use std::path::PathBuf;
use bpaf::Bpaf;
use profile_inspect::ir::FrameCategory;
#[derive(Debug, Clone, Bpaf)]
pub struct OutputOptions {
#[bpaf(short('f'), long("format"), argument("FORMAT"), many)]
pub format: Vec<String>,
#[bpaf(short('o'), long("output"), argument("DIR"))]
pub output: Option<PathBuf>,
}
impl OutputOptions {
pub fn formats(&self) -> Vec<String> {
if self.format.is_empty() {
vec!["markdown".to_string()]
} else {
self.format.clone()
}
}
}
#[derive(Debug, Clone, Bpaf)]
pub struct AnalysisOptions {
#[bpaf(long, switch)]
pub include_internals: bool,
#[bpaf(long, fallback(0.0))]
pub min_percent: f64,
#[bpaf(long, fallback(50_usize))]
pub top: usize,
}
pub fn parse_categories(filter_str: &str) -> Vec<FrameCategory> {
filter_str
.split(',')
.filter_map(|s| match s.trim().to_lowercase().as_str() {
"app" => Some(FrameCategory::App),
"deps" => Some(FrameCategory::Deps),
"node" => Some(FrameCategory::NodeInternal),
"v8" => Some(FrameCategory::V8Internal),
"native" => Some(FrameCategory::Native),
_ => None,
})
.collect()
}