diff options
| author | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:48:30 +1300 |
|---|---|---|
| committer | Ben Bridle <bridle.benjamin@gmail.com> | 2026-02-06 14:49:21 +1300 |
| commit | a5fcd1497ed5fc40c9a5efb47d201d51645e183d (patch) | |
| tree | 39382285df5eec84656cd1e9ee40d61cb53a73d1 | |
| parent | 77e7c579fa64096efad34736822b4240aad0444f (diff) | |
| download | toaster-a5fcd1497ed5fc40c9a5efb47d201d51645e183d.zip | |
Update switchboard dependency
This has no real effect on the program, it's more for tidiness.
| -rw-r--r-- | Cargo.lock | 4 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/main.rs | 85 |
3 files changed, 49 insertions, 42 deletions
@@ -107,8 +107,8 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "switchboard" -version = "1.0.0" -source = "git+git://benbridle.com/switchboard?tag=v1.0.0#ea70fa89659e5cf1a9d4ca6ea31fb67f7a2cc633" +version = "2.1.0" +source = "git+git://benbridle.com/switchboard?tag=v2.1.0#e6435712ba5b3ca36e99fc8cbe7755940f8b1f3f" dependencies = [ "log 1.1.1", "paste", @@ -8,7 +8,7 @@ vagabond = { git = "git://benbridle.com/vagabond", tag = "v1.1.1" } markdown = { git = "git://benbridle.com/markdown", tag = "v3.3.2" } recipe = { git = "git://benbridle.com/recipe", tag = "v1.4.0" } log = { git = "git://benbridle.com/log", tag = "v2.0.0" } -switchboard = { git = "git://benbridle.com/switchboard", tag = "v1.0.0" } +switchboard = { git = "git://benbridle.com/switchboard", tag = "v2.1.0" } highlight = { git = "git://benbridle.com/highlight", tag = "v1.0.2" } [profile.release] diff --git a/src/main.rs b/src/main.rs index 3ee0bc6..14a1f79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ #![feature(path_add_extension)] mod collect_files; -pub use collect_files::*; mod generate_html; +pub use collect_files::*; pub use generate_html::*; use markdown::*; @@ -12,60 +12,50 @@ use std::collections::HashSet; use std::time::SystemTime; use log::{info, warn, error, fatal}; -use switchboard::{Switchboard, SwitchQuery}; - - -fn print_help() -> ! { - eprintln!("\ -Usage: toaster <source> <destination> - -Generate a website from a structured directory of markdown files. - -Arguments: - source Source directory with markdown files - destination Path to output directory - -Switches: - --delete Delete the destination directory first if it exists - --html Generate HTML output - --version, -v Print information as each file is parsed - --version Print the program version and exit - --help, -h Print help -"); - std::process::exit(0); -} - -fn print_version() -> ! { - let version = env!("CARGO_PKG_VERSION"); - eprintln!("toaster, version {version}"); - eprintln!("written by ben bridle"); - std::process::exit(0); -} +use switchboard::*; fn main() { let mut args = Switchboard::from_env(); - if args.named("help").short('h').as_bool() { + + // Informational switches. + args.named("help").short('h'); + args.named("version"); + args.named("verbose").short('v'); + if args.get("help").as_bool() { print_help(); + std::process::exit(0); } - if args.named("version").as_bool() { - print_version(); + if args.get("version").as_bool() { + let version = env!("CARGO_PKG_VERSION"); + eprintln!("toaster, version {version}"); + eprintln!("written by ben bridle"); + std::process::exit(0); } - if args.named("verbose").short('v').as_bool() { + if args.get("verbose").as_bool() { log::set_log_level(log::LogLevel::Info); } - let source = args.positional("source").as_path(); - let destination = args.positional("destination").as_path(); - let delete_existing = args.named("delete").as_bool(); - let export_html = args.named("html").as_bool(); + // Functional switches. + args.positional("source"); + args.positional("destination"); + args.named("delete"); + args.named("html"); + args.raise_errors(); + let source = args.get("source").as_path(); + let destination = args.get("destination").as_path(); + let delete_existing = args.get("delete").as_bool(); + let export_html = args.get("html").as_bool(); + + // Parse entire website directory. let source = match source.canonicalize() { Ok(source) => source, Err(err) => fatal!("{source:?}: {err}"), }; - let website = Website::from_path(&source); + // ------------------------------------------------------------ + // Check for duplicate output paths for pages. let mut destinations: HashSet<&str> = HashSet::new(); let mut duplicates: HashSet<&str> = HashSet::new(); @@ -141,7 +131,24 @@ fn main() { } } +fn print_help() { + eprintln!("\ +Usage: toaster <source> <destination> + +Generate a website from a structured directory of markdown files. +Arguments: + source Source directory with markdown files + destination Path to output directory + +Switches: + --delete Delete the destination directory first if it exists + --html Generate HTML output + --version, -v Print information as each file is parsed + --version Print the program version and exit + --help, -h Print help +"); +} pub fn write_file(text: &str, destination: &PathBuf, ext: &str, last_modified: Option<SystemTime>) { let mut destination = destination.clone(); |
