seella/cli/
csv.rs

1use clap::Args;
2use std::{ffi::OsString, fmt::Display, ops::Deref, path::PathBuf};
3
4/// Options that are specific to the CSV mode of operation.
5#[derive(Debug, Args, Clone, Default)]
6pub struct CsvModeOptions {
7    /// The session id to be visualised
8    pub session_id: String,
9
10    /// Path to the CSV containing the sessions data. Any string that can be coerced into a PathBuf
11    #[arg(short, long, default_value_t)]
12    pub sessions_path: SessionsPath,
13
14    /// Path to the CSV containing the events data. Any string that can be coerced into a PathBuf
15    #[arg(short, long, default_value_t)]
16    pub events_path: EventsPath,
17}
18
19/// Default path to the [Session][crate::SessionRecord] source.
20///
21/// Type to provide a correct `Default::default()` PathBuf for clap.
22#[derive(Debug, Clone)]
23pub struct SessionsPath(pub PathBuf);
24
25impl Default for SessionsPath {
26    fn default() -> Self {
27        Self(PathBuf::from("sessions.csv"))
28    }
29}
30
31impl Display for SessionsPath {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        write!(f, "{}", self.0.display())
34    }
35}
36
37impl From<OsString> for SessionsPath {
38    fn from(value: OsString) -> Self {
39        Self(PathBuf::from(value))
40    }
41}
42
43impl Deref for SessionsPath {
44    type Target = PathBuf;
45
46    fn deref(&self) -> &Self::Target {
47        &self.0
48    }
49}
50
51/// Default path to the [Event][crate::EventRecord] source.
52///
53/// Type to provide a correct `Default::default()` PathBuf for clap.
54#[derive(Debug, Clone)]
55pub struct EventsPath(pub PathBuf);
56
57impl Default for EventsPath {
58    fn default() -> Self {
59        Self(PathBuf::from("events.csv"))
60    }
61}
62
63impl Display for EventsPath {
64    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65        write!(f, "{}", self.0.display())
66    }
67}
68
69impl From<OsString> for EventsPath {
70    fn from(value: OsString) -> Self {
71        Self(PathBuf::from(value))
72    }
73}
74
75impl Deref for EventsPath {
76    type Target = PathBuf;
77
78    fn deref(&self) -> &Self::Target {
79        &self.0
80    }
81}