use std::fmt;
use std::path::PathBuf;
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, ValueEnum)]
#[serde(rename_all = "kebab-case")]
pub enum Category {
RustTarget,
NodeModules,
FrameworkCache,
BuildOutput,
TestCache,
GlobalCache,
ExpensiveGlobalCache,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Confidence {
#[default]
Safe,
Review,
Protected,
}
impl Category {
#[must_use]
pub fn all() -> [Self; 7] {
[
Self::RustTarget,
Self::NodeModules,
Self::FrameworkCache,
Self::BuildOutput,
Self::TestCache,
Self::GlobalCache,
Self::ExpensiveGlobalCache,
]
}
#[must_use]
pub fn safe_defaults() -> [Self; 3] {
[Self::RustTarget, Self::NodeModules, Self::FrameworkCache]
}
}
impl fmt::Display for Category {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let value = match self {
Self::RustTarget => "rust-target",
Self::NodeModules => "node-modules",
Self::FrameworkCache => "framework-cache",
Self::BuildOutput => "build-output",
Self::TestCache => "test-cache",
Self::GlobalCache => "global-cache",
Self::ExpensiveGlobalCache => "expensive-global-cache",
};
formatter.write_str(value)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Candidate {
pub category: Category,
pub path: PathBuf,
pub bytes: u64,
pub reason: String,
pub modified_at_unix: Option<u64>,
#[serde(default)]
pub confidence: Confidence,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReviewCandidate {
pub path: PathBuf,
pub bytes: u64,
pub reason: String,
pub modified_at_unix: Option<u64>,
pub confidence: Confidence,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LearningObservation {
pub path: PathBuf,
pub category: Option<Category>,
pub bytes: u64,
pub reason: String,
pub modified_at_unix: Option<u64>,
pub confidence: Confidence,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScanReport {
pub roots: Vec<PathBuf>,
pub candidates: Vec<Candidate>,
#[serde(default)]
pub review_candidates: Vec<ReviewCandidate>,
#[serde(default)]
pub learning_observations: Vec<LearningObservation>,
pub warnings: Vec<String>,
pub total_bytes: u64,
#[serde(default)]
pub review_total_bytes: u64,
#[serde(default)]
pub observed_total_bytes: u64,
#[serde(default = "default_true")]
pub protect_git_tracked: bool,
}
const fn default_true() -> bool {
true
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum OutputFormat {
Table,
Json,
Jsonl,
Html,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct RenderOptions {
pub redact_paths: bool,
}