tikz-gallery-generator

Custum build of stapix for tikz.pablopie.xyz

Commit
d354aa8f4349c61a3333a612bb803d2c096643b2
Parent
f4f1bcff50410f655c9a62b40fb5fe4f334fc29e
Author
Pablo <pablo-escobar@riseup.net>
Date

Refactored to code for parsing argv

Also made some minor cosmetic changes

Diffstat

1 file changed, 14 insertions, 10 deletions

Status File Name N° Changes Insertions Deletions
Modified src/main.rs 24 14 10
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&apos;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&apos;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&apos;s Photo Gallery &dash; {name}</title>",
+    writeln!(f, "<title>{PAGE_TITLE} &dash; {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");
 }