Skip to content

Commit

Permalink
Merge pull request #141 from Milo123459/documentation
Browse files Browse the repository at this point in the history
Add some documentation
  • Loading branch information
coffee-cup authored May 20, 2022
2 parents b9e97ef + cdafda6 commit 9adcece
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/nixpacks/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ impl App {

Ok(App { source, paths })
}

/// Check if a file exists
pub fn includes_file(&self, name: &str) -> bool {
fs::canonicalize(self.source.join(name)).is_ok()
}

/// Returns a list of paths matching a glob pattern
///
/// # Errors
/// Creating the Glob fails
pub fn find_files(&self, pattern: &str) -> Result<Vec<PathBuf>> {
let full_pattern = self.source.join(pattern);

Expand All @@ -54,13 +58,18 @@ impl App {
Ok(relative_paths)
}

/// Check if a path matching a glob exists
pub fn has_match(&self, pattern: &str) -> bool {
match self.find_files(pattern) {
Ok(v) => !v.is_empty(),
Err(_e) => false,
}
}

/// Read the contents of a file
///
/// # Errors
/// This will error if the path doesn't exist, or if the contents isn't UTF-8
pub fn read_file(&self, name: &str) -> Result<String> {
fs::read_to_string(self.source.join(name)).map_err(|e| anyhow!(e))
}
Expand Down

0 comments on commit 9adcece

Please sign in to comment.