pub struct Folder { /* private fields */ }Expand description
The root folders, opened once, and the operator’s limits.
Implementations§
Source§impl Folder
impl Folder
Sourcepub fn open(config: Config) -> Result<Self, FolderError>
pub fn open(config: Config) -> Result<Self, FolderError>
Open the configured roots. Fails when one does not exist or is not a directory, when two roots share a name, or when a name is not a single plain path component.
Sourcepub fn roots(&self) -> impl Iterator<Item = (&str, &Path)>
pub fn roots(&self) -> impl Iterator<Item = (&str, &Path)>
Each root’s name and canonical path (for logs and doctor; never used to open files).
Sourcepub fn list(
&self,
path: &str,
glob: Option<&str>,
recursive: bool,
max_entries: Option<usize>,
) -> Result<Value, FolderError>
pub fn list( &self, path: &str, glob: Option<&str>, recursive: bool, max_entries: Option<usize>, ) -> Result<Value, FolderError>
list: entries under path (the root when empty), optionally filtered by a glob on the
path as the tools address it, one level deep unless recursive.
Sourcepub fn read(
&self,
path: &str,
start_line: Option<usize>,
end_line: Option<usize>,
) -> Result<ReadOutput, FolderError>
pub fn read( &self, path: &str, start_line: Option<usize>, end_line: Option<usize>, ) -> Result<ReadOutput, FolderError>
read: a text file, whole or lines start_line..=end_line (1-based), or a small image.
A whole-file read is refused above the size limit; a line-range read streams the file and
stops at end_line. Either returns at most the byte limit and the character limit.
Sourcepub fn search(
&self,
pattern: &str,
path: &str,
glob: Option<&str>,
ignore_case: bool,
) -> Result<Value, FolderError>
pub fn search( &self, pattern: &str, path: &str, glob: Option<&str>, ignore_case: bool, ) -> Result<Value, FolderError>
search: lines matching pattern in text files under path (or in that one file).
Sourcepub fn write(
&self,
path: &str,
content: &str,
mode: WriteMode,
) -> Result<Value, FolderError>
pub fn write( &self, path: &str, content: &str, mode: WriteMode, ) -> Result<Value, FolderError>
write: put content at path, creating parent directories.
Sourcepub fn edit(
&self,
path: &str,
old_text: &str,
new_text: &str,
replace_all: bool,
) -> Result<Value, FolderError>
pub fn edit( &self, path: &str, old_text: &str, new_text: &str, replace_all: bool, ) -> Result<Value, FolderError>
edit: replace old_text with new_text in a text file. old_text must occur exactly
once unless replace_all.
Sourcepub fn move_entry(
&self,
from: &str,
to: &str,
overwrite: bool,
) -> Result<Value, FolderError>
pub fn move_entry( &self, from: &str, to: &str, overwrite: bool, ) -> Result<Value, FolderError>
move: rename from to to (within a root or across roots); refuses to replace to
unless overwrite.
Sourcepub fn stat(&self, path: &str) -> Result<Value, FolderError>
pub fn stat(&self, path: &str) -> Result<Value, FolderError>
stat: kind, size, modified time, and line count for a text file within the size limit.
Sourcepub fn count_files(&self, stop_after: usize) -> usize
pub fn count_files(&self, stop_after: usize) -> usize
Number of files under all roots the walker sees, stopping once stop_after is passed.