use std::fs::File;
use std::io::{Write, Read, Result};
use std::path::Path;
fn main() -> Result<()> {
generate_readme_md()?;
Ok(())
}
fn generate_readme_md() -> Result<()> {
let docs_path = "doc";
let readme_path = "README.md";
let doc_filenames = vec![
"tracing_config_purpose.md",
"performance_penalties.md",
"getting_started.md",
"configuration_file_search_path.md",
"configuration_file.md",
"basic_configuration_file.md",
"reference_links.md",
];
let mut readme = String::new();
for doc_filename in doc_filenames {
let mut doc_file = File::open(format!("{}/{}", docs_path, doc_filename))?;
let mut doc_contents = String::new();
doc_file.read_to_string(&mut doc_contents)?;
readme.push_str(&doc_contents);
readme.push('\n'); readme.push('\n');
}
readme.pop();
readme.pop();
let existing_readme = if Path::new(readme_path).exists() {
let mut readme_file = File::open(readme_path)?;
let mut existing_readme = String::new();
readme_file.read_to_string(&mut existing_readme)?;
existing_readme
} else {
String::new()
};
if readme != existing_readme {
let mut readme_file = File::create(readme_path)?;
readme_file.write_all(readme.as_bytes())?;
}
Ok(())
}