use crate::{
prelude::{Network, ProgramID},
synthesizer::Program,
};
use anyhow::{ensure, Result};
use std::{
fs::File,
io::Write,
path::{Path, PathBuf},
};
pub struct README {
path: PathBuf,
}
impl README {
pub fn create<N: Network>(directory: &Path, id: &ProgramID<N>) -> Result<Self> {
ensure!(directory.exists(), "The program directory does not exist: {}", directory.display());
ensure!(!Program::is_reserved_keyword(id.name()), "Program name is invalid (reserved): {id}");
let readme_string = format!(
r"# {id}
## Build Guide
To compile this Aleo program, run:
```bash
snarkvm build
```
To execute this Aleo program, run:
```bash
snarkvm run hello
```
"
);
let file_name = "README.md".to_string();
let path = directory.join(file_name);
ensure!(!path.exists(), "README file already exists: {}", path.display());
File::create(&path)?.write_all(readme_string.as_bytes())?;
Ok(Self { path })
}
pub const fn path(&self) -> &PathBuf {
&self.path
}
}