Skip to main content

apimock_config/config/
file_tree_config.rs

1use serde::Deserialize;
2
3/// Persistent filter preferences for [`FileTreeView`], loaded from the
4/// optional `[file_tree_view]` section of `apimock.toml`.
5///
6/// When the section is absent, [`FileTreeViewConfig::default()`] is used,
7/// which mirrors [`apimock_routing::view::build::FileTreeFilter::default()`]:
8/// dotfiles hidden, built-in excludes on, no extra filters.
9///
10/// [`FileTreeView`]: apimock_routing::view::FileTreeView
11#[derive(Clone, Debug, Deserialize)]
12pub struct FileTreeViewConfig {
13    /// Show dotfiles and dot-directories (default: `false`).
14    #[serde(default)]
15    pub show_hidden: bool,
16
17    /// Apply the built-in exclude list (`target`, `node_modules`, etc.)
18    /// (default: `true`).
19    #[serde(default = "default_true")]
20    pub builtin_excludes: bool,
21
22    /// Additional entry names to exclude (exact match on `file_name()`).
23    #[serde(default)]
24    pub extra_excludes: Vec<String>,
25
26    /// If non-empty, only files whose name ends with one of these suffixes
27    /// are shown. Directories always pass the include filter so the user
28    /// can drill into them. (default: `[]` — show everything)
29    #[serde(default)]
30    pub include: Vec<String>,
31}
32
33fn default_true() -> bool {
34    true
35}
36
37impl Default for FileTreeViewConfig {
38    fn default() -> Self {
39        Self {
40            show_hidden: false,
41            builtin_excludes: true,
42            extra_excludes: Vec::new(),
43            include: Vec::new(),
44        }
45    }
46}
47
48impl FileTreeViewConfig {
49    /// Convert to the routing crate's [`FileTreeFilter`].
50    ///
51    /// [`FileTreeFilter`]: apimock_routing::view::build::FileTreeFilter
52    pub fn to_filter(&self) -> apimock_routing::view::build::FileTreeFilter {
53        apimock_routing::view::build::FileTreeFilter {
54            show_hidden: self.show_hidden,
55            builtin_excludes: self.builtin_excludes,
56            extra_excludes: self.extra_excludes.clone(),
57            include: self.include.clone(),
58        }
59    }
60}