1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::path::PathBuf;
use tokio::fs;
pub struct Changesets {
pub directory: PathBuf,
}
impl Changesets {
fn readme_path(&self) -> PathBuf {
let mut readme_path = self.directory.clone();
readme_path.push("README.md");
readme_path
}
pub fn validate(&self) -> bool {
self.directory.exists() && self.readme_path().exists()
}
pub async fn initialize(&self) -> Result<(), std::io::Error> {
if !self.directory.exists() {
fs::create_dir(&self.directory).await?;
}
fs::write(self.readme_path(), b"# Changesets directory\n\nThis directory is for changeset files, can be createted with `mol add`\n\n").await?;
Ok(())
}
}
impl Default for Changesets {
fn default() -> Self {
Changesets {
directory: [".changeset"].iter().collect(),
}
}
}