Skip to main content

tokmd_settings/
scan.rs

1//! Shared scan settings independent of clap parsing.
2
3use serde::{Deserialize, Serialize};
4use tokmd_types::ConfigMode;
5
6/// Scan options shared by all commands that invoke the scanner.
7///
8/// This mirrors the scan-relevant fields of CLI global args without any
9/// UI-specific fields (`verbose`, `no_progress`). Lower-tier crates
10/// (scan, format, model) depend on this instead of the CLI parser.
11#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct ScanOptions {
13    /// Glob patterns to exclude.
14    #[serde(default)]
15    pub excluded: Vec<String>,
16
17    /// Whether to load scan config files (`tokei.toml` / `.tokeirc`).
18    #[serde(default)]
19    pub config: ConfigMode,
20
21    /// Count hidden files and directories.
22    #[serde(default)]
23    pub hidden: bool,
24
25    /// Don't respect ignore files (.gitignore, .ignore, etc.).
26    #[serde(default)]
27    pub no_ignore: bool,
28
29    /// Don't respect ignore files in parent directories.
30    #[serde(default)]
31    pub no_ignore_parent: bool,
32
33    /// Don't respect .ignore and .tokeignore files.
34    #[serde(default)]
35    pub no_ignore_dot: bool,
36
37    /// Don't respect VCS ignore files (.gitignore, .hgignore, etc.).
38    #[serde(default)]
39    pub no_ignore_vcs: bool,
40
41    /// Treat doc strings as comments.
42    #[serde(default)]
43    pub treat_doc_strings_as_comments: bool,
44}
45
46/// Global scan settings shared by all operations.
47#[derive(Debug, Clone, Default, Serialize, Deserialize)]
48pub struct ScanSettings {
49    /// Paths to scan (defaults to `["."]`).
50    #[serde(default)]
51    pub paths: Vec<String>,
52
53    /// Scan options (excludes, ignore flags, etc.).
54    #[serde(flatten)]
55    pub options: ScanOptions,
56}
57
58impl ScanSettings {
59    /// Create settings for scanning the current directory with defaults.
60    pub fn current_dir() -> Self {
61        Self {
62            paths: vec![".".to_string()],
63            ..Default::default()
64        }
65    }
66
67    /// Create settings for scanning specific paths.
68    pub fn for_paths(paths: Vec<String>) -> Self {
69        Self {
70            paths,
71            ..Default::default()
72        }
73    }
74}