summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml1
-rw-r--r--src/collect_files.rs8
-rw-r--r--src/main.rs41
4 files changed, 19 insertions, 37 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0579687..451856b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,11 @@
version = 4
[[package]]
+name = "log"
+version = "1.1.1"
+source = "git+git://benbridle.com/log?tag=v1.1.1#930f3d0e2b82df1243f423c092a38546ea7533c3"
+
+[[package]]
name = "markdown"
version = "3.2.0"
source = "git+git://benbridle.com/markdown?tag=v3.2.0#883a2a63023ea9b1e4b2bb51831ea1dafcb7346a"
@@ -16,6 +21,7 @@ source = "git+git://benbridle.com/recipe?tag=v1.4.0#652aaee3130e2ee02742fdcc248d
name = "toaster"
version = "1.8.0"
dependencies = [
+ "log",
"markdown",
"recipe",
"vagabond",
diff --git a/Cargo.toml b/Cargo.toml
index a54a8c9..a84de6e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2021"
vagabond = { git = "git://benbridle.com/vagabond", tag = "v1.1.0" }
markdown = { git = "git://benbridle.com/markdown", tag = "v3.2.0" }
recipe = { git = "git://benbridle.com/recipe", tag = "v1.4.0" }
+log = { git = "git://benbridle.com/log", tag = "v1.1.1" }
xflags = "0.4.0-pre.1"
[profile.release]
diff --git a/src/collect_files.rs b/src/collect_files.rs
index 4eee1dc..7a3c464 100644
--- a/src/collect_files.rs
+++ b/src/collect_files.rs
@@ -93,7 +93,7 @@ impl Website {
static_dirs: Vec::new(),
name: match Entry::from_path(path) {
Ok(entry) => entry.name,
- Err(err) => error!("Couldn't open {:?}: {:?}", &path, err),
+ Err(err) => fatal!("Couldn't open {:?}: {:?}", &path, err),
},
config: HashMap::new(),
};
@@ -118,7 +118,7 @@ impl Website {
// Generate parent URL, used only for files.
let source_path = entry.original_path.clone();
let relative_path = source_path.strip_prefix(prefix).unwrap_or_else(
- |_| error!("Path doesn't start with {prefix:?}: {source_path:?}"));
+ |_| fatal!("Path doesn't start with {prefix:?}: {source_path:?}"));
let mut parents: Vec<_> = relative_path.components()
.map(|c| c.as_os_str().to_string_lossy().to_string()).collect();
parents.pop(); // Remove file segment.
@@ -130,7 +130,7 @@ impl Website {
for child in traverse_directory(&entry).unwrap() {
let source_path = child.original_path;
let relative_path = source_path.strip_prefix(&entry.original_path).unwrap_or_else(
- |_| error!("Path doesn't start with {prefix:?}: {source_path:?}"))
+ |_| fatal!("Path doesn't start with {prefix:?}: {source_path:?}"))
.as_os_str().to_string_lossy().to_string();
let full_url = format!("{stripped}/{relative_path}");
self.static_files.push(StaticItem { full_url, source_path, last_modified })
@@ -143,7 +143,7 @@ impl Website {
}
}
} else if parents.is_empty() && entry.name.to_lowercase() == "toaster.conf" {
- verbose!("Reading configuration file at {path:?}");
+ info!("Reading configuration file at {path:?}");
// Parse the config file.
let config = std::fs::read_to_string(&source_path).unwrap();
let mut key = None;
diff --git a/src/main.rs b/src/main.rs
index 25d1528..82814e4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,33 +11,8 @@ use vagabond::*;
use std::collections::HashSet;
use std::time::SystemTime;
+use log::{info, warn, error, fatal};
-const NORMAL: &str = "\x1b[0m";
-const BOLD: &str = "\x1b[1m";
-const WHITE: &str = "\x1b[37m";
-const RED: &str = "\x1b[31m";
-const YELLOW: &str = "\x1b[33m";
-const BLUE: &str = "\x1b[34m";
-
-static mut VERBOSE: bool = false;
-#[macro_export] macro_rules! verbose {
- ($($tokens:tt)*) => { if unsafe { VERBOSE } {
- eprint!("{BOLD}{BLUE}[INFO]{NORMAL}: "); eprint!($($tokens)*);
- eprintln!("{NORMAL}");
- } };
-}
-#[macro_export] macro_rules! warn {
- ($($tokens:tt)*) => {{
- eprint!("{BOLD}{YELLOW}[WARNING]{NORMAL}{WHITE}: "); eprint!($($tokens)*);
- eprintln!("{NORMAL}");
- }};
-}
-#[macro_export] macro_rules! error {
- ($($tokens:tt)*) => {{
- eprint!("{BOLD}{RED}[ERROR]{WHITE}: "); eprint!($($tokens)*);
- eprintln!("{NORMAL}"); std::process::exit(1);
- }};
-}
fn main() {
let args = Arguments::from_env_or_exit();
@@ -47,14 +22,14 @@ fn main() {
std::process::exit(0);
}
if args.verbose {
- unsafe { VERBOSE = true; }
+ log::set_log_level(log::LogLevel::Info);
}
if args.source.is_none() || args.destination.is_none() {
- error!("Provide a source directory and a destination directory.")
+ fatal!("Provide a source directory and a destination directory.")
}
let source_directory = match args.source.as_ref().unwrap().canonicalize() {
Ok(source_directory) => source_directory,
- Err(err) => error!("{:?}: {err}", args.source.unwrap()),
+ Err(err) => fatal!("{:?}: {err}", args.source.unwrap()),
};
let destination_directory = args.destination.unwrap();
@@ -84,7 +59,7 @@ fn main() {
destination.push(make_url_safe(&website.name));
if args.delete && Entry::from_path(&destination).is_ok() {
- verbose!("Deleting existing destination directory {destination:?}");
+ info!("Deleting existing destination directory {destination:?}");
remove(&destination).unwrap_or_else(|_|
error!("Failed to delete existing destination directory {destination:?}"));
}
@@ -100,7 +75,7 @@ fn main() {
}
// Copy original markdown file.
destination.add_extension("md");
- verbose!("Copying original markdown file to {destination:?}");
+ info!("Copying original markdown file to {destination:?}");
copy(&page.source_path, &destination).unwrap_or_else(|_|
error!("Failed to copy original markdown file {:?} to {:?}",
page.source_path, destination));
@@ -109,7 +84,7 @@ fn main() {
for static_file in &website.static_files {
let mut destination = destination.clone();
destination.push(&static_file.full_url);
- verbose!("Copying static file to {destination:?}");
+ info!("Copying static file to {destination:?}");
make_parent_directory(&destination).unwrap();
copy(&static_file.source_path, &destination).unwrap_or_else(|_|
error!("Failed to copy static file {:?} to {:?}",
@@ -141,7 +116,7 @@ fn main() {
pub fn write_file(text: &str, destination: &PathBuf, ext: &str, last_modified: Option<SystemTime>) {
let mut destination = destination.clone();
destination.add_extension(ext);
- verbose!("Generating {destination:?}");
+ info!("Generating {destination:?}");
make_parent_directory(&destination).unwrap_or_else(|_|
error!("Failed to create parent directories for {destination:?}"));
write_to_file(&destination, text).unwrap_or_else(|_|