diff --git a/src/main.rs b/src/main.rs
@@ -8,21 +8,24 @@ use serde_yaml;
mod types;
+const PAGE_TITLE: &'static str = "Pablo's Photo Gallery";
+
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
- let config = match args.len() {
- 2 => &args[1],
- 1 => {
+ let config = match &args[..] {
+ [_, config] => config,
+ [program] => {
eprintln!("ERROR: Expected one command line argument, found none");
- usage();
+ usage(program);
exit(1)
},
- _ => {
+ [program, ..] => {
eprintln!("ERROR: Expected one command line argument, found many");
- usage();
+ usage(program);
exit(1)
},
+ [] => unreachable!("args always contains at least the input program")
};
let f = File::open(&config);
@@ -34,6 +37,7 @@ fn main() -> io::Result<()> {
},
// Error parsing the config file
Ok(Err(err)) => {
+ // TODO: Print a message explaining the format of the config file
eprintln!("ERROR: Couldn't parse {config:?}: {err}");
exit(1)
},
@@ -79,7 +83,7 @@ fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> {
write_license(&mut f)?;
writeln!(f, "<html lang=\"en\">")?;
writeln!(f, "<head>")?;
- writeln!(f, "<title>Pablo's Photo Gallery</title>")?;
+ writeln!(f, "<title>{PAGE_TITLE}</title>")?;
write_head(&mut f)?;
for pic in pic_infos {
@@ -132,7 +136,7 @@ fn render_pic_page(pic: &PictureInfo) -> io::Result<()> {
write_license(&mut f)?;
writeln!(f, "<html lang=\"en\">")?;
writeln!(f, "<head>")?;
- writeln!(f, "<title>Pablo's Photo Gallery ‐ {name}</title>",
+ writeln!(f, "<title>{PAGE_TITLE} ‐ {name}</title>",
name = Escaped(&pic.file_name))?;
write_head(&mut f)?;
writeln!(f,
@@ -197,6 +201,6 @@ fn write_license(f: &mut File) -> io::Result<()> {
writeln!(f, " along with this program. If not, see <https://www.gnu.org/licenses/>. -->")
}
-fn usage() {
- eprintln!("USAGE: yaggen config.yml");
+fn usage(program: &str) {
+ eprintln!("Usage: {program} config.yml");
}