- Commit
- 7c36a5102fc68130274d70871a140e969e46e019
- Parent
- 63e85c85bc8e7c8e344ccf5a004f06624f6af59d
- Author
- Pablo <pablo-escobar@riseup.net>
- Date
Structed the entrypoint of the application
Yet another static page generator for photo galleries
Structed the entrypoint of the application
2 files changed, 55 insertions, 7 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | .gitignore | 2 | 2 | 0 |
Modified | src/main.rs | 60 | 53 | 7 |
diff --git a/.gitignore b/.gitignore @@ -1 +1,3 @@ /target +/photos +photos.yml
diff --git a/src/main.rs b/src/main.rs @@ -1,14 +1,60 @@ +use std::{io, env}; +use std::process::exit; +use std::fs::File; use picture_info::PictureInfo; use serde_yaml; mod picture_info; -fn main() { - let yaml = " - - path: \"photos/pic.jpg\" - - path: \"photos/another-pic.png\" - "; - let pic_info: Vec<PictureInfo> = serde_yaml::from_str(yaml).unwrap(); +fn main() -> io::Result<()> { + let args: Vec<String> = env::args().collect(); - println!("{pic_info:?}"); + let config = match args.len() { + 2 => &args[1], + 1 => { + // TODO: Print usage info + eprintln!("ERROR: Expected one command line argument, found none"); + exit(1) + }, + _ => { + // TODO: Print usage info + eprintln!("ERROR: Expected one command line argument, found many"); + exit(1) + }, + }; + + let f = File::open(config); + match f.map(serde_yaml::from_reader::<_, Vec<PictureInfo>>) { + // Error opening the config file + Err(err) => { + eprintln!("ERROR: {err}"); + Err(err) + }, + // Error parsing the config file + Ok(Err(err)) => { + eprintln!("ERROR: {err}"); + exit(1) + }, + Ok(Ok(pic_infos)) => render_gallery(pic_infos), + } +} + +/// Coordinates the rendering of all the pages and file conversions +fn render_gallery(pic_infos: Vec<PictureInfo>) -> io::Result<()> { + render_index(&pic_infos)?; + + for pic in pic_infos { + render_pic_page(&pic)?; + } + + Ok(()) +} + +fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> { + for pic in pic_infos { println!("{pic:?}"); } + Ok(()) +} + +fn render_pic_page(_pic: &PictureInfo) -> io::Result<()> { + Ok(()) }