use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FilesystemItem {
File {
path: String,
comment: Option<String>,
},
Directory {
path: String,
comment: Option<String>,
children: Vec<NavigationGuideLine>,
},
Symlink {
path: String,
comment: Option<String>,
target: Option<String>,
},
Placeholder {
comment: Option<String>,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NavigationGuideLine {
pub line_number: usize,
pub indent_level: usize,
pub item: FilesystemItem,
}
impl NavigationGuideLine {
pub fn path(&self) -> &str {
match &self.item {
FilesystemItem::File { path, .. }
| FilesystemItem::Directory { path, .. }
| FilesystemItem::Symlink { path, .. } => path,
FilesystemItem::Placeholder { .. } => "...",
}
}
pub fn comment(&self) -> Option<&str> {
match &self.item {
FilesystemItem::File { comment, .. }
| FilesystemItem::Directory { comment, .. }
| FilesystemItem::Symlink { comment, .. }
| FilesystemItem::Placeholder { comment, .. } => comment.as_deref(),
}
}
pub fn is_directory(&self) -> bool {
matches!(self.item, FilesystemItem::Directory { .. })
}
pub fn is_placeholder(&self) -> bool {
matches!(self.item, FilesystemItem::Placeholder { .. })
}
pub fn children(&self) -> Option<&[NavigationGuideLine]> {
match &self.item {
FilesystemItem::Directory { children, .. } => Some(children),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NavigationGuide {
pub items: Vec<NavigationGuideLine>,
pub prologue: Option<String>,
pub epilogue: Option<String>,
pub ignore: bool,
}
impl NavigationGuide {
pub fn new() -> Self {
Self {
items: Vec::new(),
prologue: None,
epilogue: None,
ignore: false,
}
}
pub fn get_full_path(&self, item: &NavigationGuideLine) -> PathBuf {
PathBuf::from(item.path())
}
}
impl Default for NavigationGuide {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ExecutionMode {
Default,
PostToolUse,
PreCommitHook,
GitHubActions,
}
impl Default for ExecutionMode {
fn default() -> Self {
Self::Default
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum LogLevel {
Quiet,
Default,
Verbose,
}
impl Default for LogLevel {
fn default() -> Self {
Self::Default
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Config {
pub execution_mode: ExecutionMode,
pub log_level: LogLevel,
pub root_path: Option<PathBuf>,
pub guide_path: Option<PathBuf>,
pub original_guide_path: Option<String>,
pub original_root_path: Option<String>,
}