summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs85
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();