use clap::{Parser, Subcommand, ValueEnum};
use std::{fmt::Display, num::ParseIntError, ops::Deref, str::FromStr};
mod csv;
mod db;
pub use csv::{CsvModeOptions, EventsPath, SessionsPath};
pub use db::{DbAddr, DbModeOptions};
#[derive(Debug, Parser, Default)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub mode: OperationMode,
#[arg(short, long, default_value_t)]
pub waterfall_width: WaterfallWidth,
#[arg(value_enum, short, long, default_value_t)]
pub duration_format: DurationFormat,
#[arg(long, default_value_t)]
pub min_duration_width: MinDurationWidth,
#[arg(long, default_value_t)]
pub max_activity_width: MaxActivityWidth,
#[arg(long)]
pub show_event_id: bool,
#[arg(long)]
pub show_span_ids: bool,
#[arg(long)]
pub show_thread: bool,
}
#[derive(Debug, Subcommand, Clone)]
pub enum OperationMode {
Csv(CsvModeOptions),
Db(DbModeOptions),
}
impl Default for OperationMode {
fn default() -> Self {
OperationMode::Csv(CsvModeOptions::default())
}
}
#[derive(Debug, Clone)]
pub struct WaterfallWidth(pub usize);
impl Default for WaterfallWidth {
fn default() -> Self {
Self(100)
}
}
impl Display for WaterfallWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl FromStr for WaterfallWidth {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(usize::from_str(s)?))
}
}
impl Deref for WaterfallWidth {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Default, Clone, ValueEnum)]
pub enum DurationFormat {
Millis,
#[default]
Micros,
}
#[derive(Debug, Clone)]
pub struct MinDurationWidth(pub usize);
impl Default for MinDurationWidth {
fn default() -> Self {
Self(6)
}
}
impl Display for MinDurationWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl FromStr for MinDurationWidth {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(usize::from_str(s)?))
}
}
impl Deref for MinDurationWidth {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone)]
pub struct MaxActivityWidth(pub usize);
impl Default for MaxActivityWidth {
fn default() -> Self {
Self(300)
}
}
impl Display for MaxActivityWidth {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl FromStr for MaxActivityWidth {
type Err = ParseIntError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(usize::from_str(s)?))
}
}
impl Deref for MaxActivityWidth {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.0
}
}