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 /src/main.rs | |
| parent | 77e7c579fa64096efad34736822b4240aad0444f (diff) | |
| download | toaster-a5fcd1497ed5fc40c9a5efb47d201d51645e183d.zip | |
Update switchboard dependency
This has no real effect on the program, it's more for tidiness.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 85 |
1 files changed, 46 insertions, 39 deletions
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(); |
