3 /// Determines which files should be read or ignored during directory walking
4 pub struct FileVisibilityPolicy {
5 /// Enables reading .ignore files.
7 /// Disabled by default.
10 /// If enabled, ignores hidden files.
12 /// Disabled by default
13 pub read_hidden: bool,
15 /// Enables reading .gitignore files.
17 /// This is enabled by default.
18 pub read_git_ignore: bool,
20 /// Enables reading `.git/info/exclude` files.
21 pub read_git_exclude: bool,
24 impl Default for FileVisibilityPolicy {
25 fn default() -> Self {
29 read_git_ignore: false,
30 read_git_exclude: false,
35 impl FileVisibilityPolicy {
36 pub fn new() -> Self {
41 /// Enables reading .ignore files.
42 pub fn read_ignore(self, read_ignore: bool) -> Self {
43 Self { read_ignore, ..self }
47 /// Enables reading .gitignore files.
48 pub fn read_git_ignore(self, read_git_ignore: bool) -> Self {
56 /// Enables reading `.git/info/exclude` files.
57 pub fn read_git_exclude(self, read_git_exclude: bool) -> Self {
65 /// Enables reading `.git/info/exclude` files.
66 pub fn read_hidden(self, read_hidden: bool) -> Self {
67 Self { read_hidden, ..self }
70 /// Walks through a directory using [`ignore::Walk`]
71 pub fn build_walker(&self, path: impl AsRef<Path>) -> ignore::Walk {
72 ignore::WalkBuilder::new(path)
73 .git_exclude(self.read_git_exclude)
74 .git_ignore(self.read_git_ignore)
75 .ignore(self.read_ignore)
76 .hidden(self.read_hidden)