Schneider
5 years ago
6 changed files with 72 additions and 1 deletions
-
35Cargo.lock
-
2Cargo.toml
-
6src/app.rs
-
28src/gitignore.rs
-
1src/helpers.rs
-
1src/main.rs
@ -0,0 +1,28 @@ |
|||
use crate::errors::*;
|
|||
use std::fs::OpenOptions;
|
|||
use std::path::PathBuf;
|
|||
|
|||
/// An abstraction of the gitignore file
|
|||
#[derive(Debug, Default)]
|
|||
pub struct Gitignore {
|
|||
/// The path to the gitignore
|
|||
path: PathBuf,
|
|||
}
|
|||
impl Gitignore {
|
|||
/// Create a new Gitignore struct from a git root folder path
|
|||
///
|
|||
/// The given `path` must be a valid path to an existing git root folder
|
|||
pub fn from_path(path: &PathBuf) -> Self { Gitignore { path: path.clone() } }
|
|||
|
|||
/// Append a line to the file
|
|||
pub fn add_line(&self, line: &str) -> Result<()> {
|
|||
use std::io::prelude::*;
|
|||
let mut file = OpenOptions::new()
|
|||
.write(true)
|
|||
.append(true)
|
|||
.open(&self.path)
|
|||
.chain_err(|| "Error while opening gitignore file")?;
|
|||
writeln!(file, "{}", line).chain_err(|| "Error while writing line to gitignore")?;
|
|||
Ok(())
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue