aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-07-18 13:22:04 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-07-18 13:22:04 +0200
commit8d11eb64efa67f1d7a6902300fdffd2c7c08df6c (patch)
tree119de904ee30468726d7f58680e1ba47c5dd267e /src
parent5d8b65a9a5742e5db705cf4c8164138eca20c355 (diff)
Apply clippy and formatting
Diffstat (limited to 'src')
-rw-r--r--src/archiver/gemini.rs4
-rw-r--r--src/archiver/gopher.rs4
-rw-r--r--src/archiver/mod.rs4
-rw-r--r--src/command/add_remote.rs4
-rw-r--r--src/command/publish.rs8
-rw-r--r--src/command/publish_archive.rs8
-rw-r--r--src/command/status/blog_status.rs6
-rw-r--r--src/command/status/configuration_status.rs10
-rw-r--r--src/generator/html.rs4
-rw-r--r--src/generator/rss.rs4
-rw-r--r--src/generator/txt.rs4
-rw-r--r--src/remote/git.rs8
-rw-r--r--src/remote/mod.rs12
-rw-r--r--src/template.rs27
14 files changed, 50 insertions, 57 deletions
diff --git a/src/archiver/gemini.rs b/src/archiver/gemini.rs
index f4df9f8..edc6219 100644
--- a/src/archiver/gemini.rs
+++ b/src/archiver/gemini.rs
@@ -1,6 +1,6 @@
use crate::template::{Context, find, parse};
use std::fs::write;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const FILENAME: &str = "index.gmi";
@@ -13,7 +13,7 @@ pub fn archive(
) -> Result<()> {
if let Some(template) = find(template_directory, FILENAME) {
let parsed_template = parse(&template)
- .ok_or_else(|| Error::new(Other, "Unable to parse Gemini Archive template"))?;
+ .ok_or_else(|| Error::other("Unable to parse Gemini Archive template"))?;
let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
diff --git a/src/archiver/gopher.rs b/src/archiver/gopher.rs
index 8c37022..39b54cb 100644
--- a/src/archiver/gopher.rs
+++ b/src/archiver/gopher.rs
@@ -1,6 +1,6 @@
use crate::template::{Context, find, parse};
use std::fs::write;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const FILENAME: &str = "index.gph";
@@ -13,7 +13,7 @@ pub fn archive(
) -> Result<()> {
if let Some(template) = find(template_directory, FILENAME) {
let parsed_template = parse(&template)
- .ok_or_else(|| Error::new(Other, "Unable to parse Gopher Archive template"))?;
+ .ok_or_else(|| Error::other("Unable to parse Gopher Archive template"))?;
let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
diff --git a/src/archiver/mod.rs b/src/archiver/mod.rs
index db3a841..a0655a4 100644
--- a/src/archiver/mod.rs
+++ b/src/archiver/mod.rs
@@ -5,7 +5,7 @@ mod raw;
use crate::template::{Context, Value};
use std::collections::HashMap;
use std::fs::read_dir;
-use std::io::{Error, ErrorKind, Result};
+use std::io::{Error, Result};
use std::path::{Path, PathBuf};
use time::{OffsetDateTime, format_description::FormatItem, macros::format_description};
@@ -30,7 +30,7 @@ impl ArchiveEntry {
let archive_length: u64 = archive_entries
.len()
.try_into()
- .map_err(|_| Error::new(ErrorKind::Other, "Too many items in the archive."))?;
+ .map_err(|_| Error::other("Too many items in the archive."))?;
context.insert(
"archive_length".to_string(),
Value::Unsigned(archive_length),
diff --git a/src/command/add_remote.rs b/src/command/add_remote.rs
index aa3f745..d22d484 100644
--- a/src/command/add_remote.rs
+++ b/src/command/add_remote.rs
@@ -1,6 +1,6 @@
use crate::configuration::Configuration;
use crate::remote::add;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
pub struct AddRemote;
@@ -22,7 +22,7 @@ impl super::Command for AddRemote {
_: &str,
) -> Result<()> {
let input = input
- .ok_or_else(|| Error::new(Other, "You must provide a location for the remote."))?;
+ .ok_or_else(|| Error::other("You must provide a location for the remote."))?;
add(
&configuration.config_directory,
&configuration.remote_config,
diff --git a/src/command/publish.rs b/src/command/publish.rs
index 388792f..4b174de 100644
--- a/src/command/publish.rs
+++ b/src/command/publish.rs
@@ -1,5 +1,5 @@
use crate::configuration::Configuration;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::process::{Command, Stdio};
const COMMAND: &str = "rsync";
@@ -24,14 +24,14 @@ impl super::Command for Publish {
_: &str,
) -> Result<()> {
let input = input
- .ok_or_else(|| Error::new(Other, "You must provide a location to publish the blog"))?;
+ .ok_or_else(|| Error::other("You must provide a location to publish the blog"))?;
Command::new(COMMAND)
.arg("--version")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Publishing requires rsync"))?;
+ .map_err(|_| Error::other("Publishing requires rsync"))?;
Command::new(COMMAND)
.arg("-r")
@@ -43,7 +43,7 @@ impl super::Command for Publish {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Rsync failed to publish."))?;
+ .map_err(|_| Error::other("Rsync failed to publish."))?;
Ok(())
}
diff --git a/src/command/publish_archive.rs b/src/command/publish_archive.rs
index 96dda86..289b0c8 100644
--- a/src/command/publish_archive.rs
+++ b/src/command/publish_archive.rs
@@ -1,5 +1,5 @@
use crate::configuration::Configuration;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::process::{Command, Stdio};
const COMMAND: &str = "rsync";
@@ -24,7 +24,7 @@ impl super::Command for PublishArchive {
_: &str,
) -> Result<()> {
let input = input.ok_or_else(|| {
- Error::new(Other, "You must provide a location to publish the archive")
+ Error::other("You must provide a location to publish the archive")
})?;
Command::new(COMMAND)
@@ -32,7 +32,7 @@ impl super::Command for PublishArchive {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Publishing requires rsync"))?;
+ .map_err(|_| Error::other("Publishing requires rsync"))?;
Command::new(COMMAND)
.arg("-r")
@@ -44,7 +44,7 @@ impl super::Command for PublishArchive {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Rsync failed to publish."))?;
+ .map_err(|_| Error::other("Rsync failed to publish."))?;
Ok(())
}
diff --git a/src/command/status/blog_status.rs b/src/command/status/blog_status.rs
index 32881d0..cae101a 100644
--- a/src/command/status/blog_status.rs
+++ b/src/command/status/blog_status.rs
@@ -1,7 +1,7 @@
use crate::configuration::Configuration;
use std::fmt::Write;
use std::fs::read_dir;
-use std::io::{Error, ErrorKind, Result};
+use std::io::{Error, Result};
use std::path::PathBuf;
pub fn status(configuration: &Configuration) -> Result<String> {
@@ -12,14 +12,14 @@ pub fn status(configuration: &Configuration) -> Result<String> {
// Main Configuration Locations
let blog_count = count_entries(&configuration.posts_directory);
writeln!(&mut status_message, "Number of posts in blog: {blog_count}")
- .map_err(|_| Error::new(ErrorKind::Other, "Unable to write status"))?;
+ .map_err(|_| Error::other("Unable to write status"))?;
let archive_count = count_entries(&configuration.archive_directory);
writeln!(
&mut status_message,
"Number of posts in archive: {archive_count}"
)
- .map_err(|_| Error::new(ErrorKind::Other, "Unable to write status"))?;
+ .map_err(|_| Error::other("Unable to write status"))?;
Ok(status_message)
}
diff --git a/src/command/status/configuration_status.rs b/src/command/status/configuration_status.rs
index 6f7db14..4a01768 100644
--- a/src/command/status/configuration_status.rs
+++ b/src/command/status/configuration_status.rs
@@ -1,7 +1,7 @@
use crate::configuration::Configuration;
use std::fmt::Write;
use std::fs;
-use std::io::{Error, ErrorKind, Result};
+use std::io::{Error, Result};
use std::path::PathBuf;
pub fn status(configuration: &Configuration) -> Result<String> {
@@ -27,7 +27,7 @@ pub fn status(configuration: &Configuration) -> Result<String> {
"Number of posts to keep: {}",
configuration.max_posts
)
- .map_err(|_| Error::new(ErrorKind::Other, "Unable to write status"))?;
+ .map_err(|_| Error::other("Unable to write status"))?;
Ok(status_message)
}
@@ -35,7 +35,7 @@ fn get_directory_stats(label: &str, directory: &PathBuf) -> Result<String> {
let mut status_message = String::new();
write!(&mut status_message, "{}: {}. ", label, directory.display())
- .map_err(|_| Error::new(ErrorKind::Other, "Unable to write status"))?;
+ .map_err(|_| Error::other("Unable to write status"))?;
if directory.exists() {
status_message.push_str("Exists ");
if fs::read_dir(directory).is_ok() {
@@ -52,7 +52,7 @@ fn get_directory_stats(label: &str, directory: &PathBuf) -> Result<String> {
#[cfg(test)]
mod tests {
- use std::fs::{Permissions, create_dir_all, metadata, set_permissions};
+ use std::fs::{metadata, set_permissions};
use std::path::PathBuf;
#[cfg(unix)]
@@ -61,7 +61,7 @@ mod tests {
#[cfg(windows)]
use std::os::windows::fs::PermissionsExt;
- use crate::configuration::Configuration;
+
use test_utilities::*;
diff --git a/src/generator/html.rs b/src/generator/html.rs
index ade3eee..0e24e64 100644
--- a/src/generator/html.rs
+++ b/src/generator/html.rs
@@ -1,6 +1,6 @@
use crate::template::{Context, find, parse};
use std::fs::write;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const FILENAME: &str = "index.html";
@@ -13,7 +13,7 @@ pub fn generate(
) -> Result<()> {
if let Some(template) = find(template_directory, FILENAME) {
let parsed_template =
- parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse HTML template"))?;
+ parse(&template).ok_or_else(|| Error::other("Unable to parse HTML template"))?;
let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
diff --git a/src/generator/rss.rs b/src/generator/rss.rs
index a36ad14..39b2062 100644
--- a/src/generator/rss.rs
+++ b/src/generator/rss.rs
@@ -1,6 +1,6 @@
use crate::template::{Context, find, parse};
use std::fs::write;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const FILENAME: &str = "feed.xml";
@@ -13,7 +13,7 @@ pub fn generate(
) -> Result<()> {
if let Some(template) = find(template_directory, FILENAME) {
let parsed_template =
- parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse RSS template"))?;
+ parse(&template).ok_or_else(|| Error::other("Unable to parse RSS template"))?;
let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
diff --git a/src/generator/txt.rs b/src/generator/txt.rs
index cc590a4..6915812 100644
--- a/src/generator/txt.rs
+++ b/src/generator/txt.rs
@@ -1,6 +1,6 @@
use crate::template::{Context, find, parse};
use std::fs::write;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const FILENAME: &str = "index.txt";
@@ -13,7 +13,7 @@ pub fn generate(
) -> Result<()> {
if let Some(template) = find(template_directory, FILENAME) {
let parsed_template =
- parse(&template).ok_or_else(|| Error::new(Other, "Unable to parse TXT template"))?;
+ parse(&template).ok_or_else(|| Error::other("Unable to parse TXT template"))?;
let rendered_template = parsed_template.render(context)?;
let location = target.join(FILENAME);
write(location, rendered_template)?;
diff --git a/src/remote/git.rs b/src/remote/git.rs
index 3290793..c8aaf46 100644
--- a/src/remote/git.rs
+++ b/src/remote/git.rs
@@ -1,4 +1,4 @@
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
use std::process::{Command, Stdio};
use std::time::{SystemTime, UNIX_EPOCH};
@@ -27,7 +27,7 @@ impl super::Remote for Git {
fn sync_up(&self, remote: &str, directory: &Path) -> Result<()> {
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
- .map_err(|_| Error::new(Other, "Invalid time"))?
+ .map_err(|_| Error::other("Invalid time"))?
.as_millis();
let commit_name = format!("blog-sync-up-{timestamp}");
@@ -45,7 +45,7 @@ impl super::Remote for Git {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Failed while performing sync up with git"))?;
+ .map_err(|_| Error::other("Failed while performing sync up with git"))?;
}
Ok(())
@@ -66,7 +66,7 @@ impl super::Remote for Git {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
- .map_err(|_| Error::new(Other, "Failed while performing sync down with git"))?;
+ .map_err(|_| Error::other("Failed while performing sync down with git"))?;
}
Ok(())
}
diff --git a/src/remote/mod.rs b/src/remote/mod.rs
index 90f400c..5fc73cc 100644
--- a/src/remote/mod.rs
+++ b/src/remote/mod.rs
@@ -1,7 +1,7 @@
mod git;
use std::fs::{File, create_dir_all, remove_file, write};
-use std::io::{Error, ErrorKind::Other, Read, Result};
+use std::io::{Error, Read, Result};
use std::path::Path;
use git::Git;
@@ -27,7 +27,7 @@ pub fn remove(remote_config: &Path) -> Result<()> {
pub fn sync_up(data_directory: &Path, remote_config: &Path) -> Result<()> {
let remote_address =
- read_remote(remote_config).ok_or_else(|| Error::new(Other, "No remote is configured"))?;
+ read_remote(remote_config).ok_or_else(|| Error::other("No remote is configured"))?;
create_dir_all(data_directory)?;
let remotes = available_remotes();
for remote in remotes {
@@ -35,15 +35,14 @@ pub fn sync_up(data_directory: &Path, remote_config: &Path) -> Result<()> {
return remote.sync_up(&remote_address, data_directory);
}
}
- Err(Error::new(
- Other,
+ Err(Error::other(
"No valid strategies found for your configured remote.",
))
}
pub fn sync_down(data_directory: &Path, remote_config: &Path) -> Result<()> {
let remote_address =
- read_remote(remote_config).ok_or_else(|| Error::new(Other, "No remote is configured"))?;
+ read_remote(remote_config).ok_or_else(|| Error::other("No remote is configured"))?;
create_dir_all(data_directory)?;
let remotes = available_remotes();
for remote in remotes {
@@ -51,8 +50,7 @@ pub fn sync_down(data_directory: &Path, remote_config: &Path) -> Result<()> {
return remote.sync_down(&remote_address, data_directory);
}
}
- Err(Error::new(
- Other,
+ Err(Error::other(
"No valid strategies found for your configured remote.",
))
}
diff --git a/src/template.rs b/src/template.rs
index bba0bbb..1a00fe2 100644
--- a/src/template.rs
+++ b/src/template.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
-use std::io::{Error, ErrorKind::Other, Result};
+use std::io::{Error, Result};
use std::path::Path;
const TXT_TEMPLATE: &str = include_str!("../templates/index.txt");
@@ -118,7 +118,7 @@ impl Parsed {
Token::Text(contents) => rendered_template.push_str(contents),
Token::DisplayDirective { content } => {
let value = ContextGetter::get(context, content).ok_or_else(|| {
- Error::new(Other, format!("{content} is not a valid key"))
+ Error::other(format!("{content} is not a valid key"))
})?;
rendered_template.push_str(&value.render());
}
@@ -134,7 +134,7 @@ impl Parsed {
}
let value = ContextGetter::get(context, &condition).ok_or_else(|| {
- Error::new(Other, format!("{condition} is not a valid key"))
+ Error::other(format!("{condition} is not a valid key"))
})?;
match value {
@@ -145,8 +145,7 @@ impl Parsed {
}
Ok(())
}
- _ => Err(Error::new(
- Other,
+ _ => Err(Error::other(
format!("{condition} is not a boolean value"),
)),
}?;
@@ -157,7 +156,7 @@ impl Parsed {
children,
} => {
let value = ContextGetter::get(context, collection).ok_or_else(|| {
- Error::new(Other, format!("{collection} is not a valid key"))
+ Error::other(format!("{collection} is not a valid key"))
})?;
match value {
@@ -171,8 +170,7 @@ impl Parsed {
}
Ok(())
}
- _ => Err(Error::new(
- Other,
+ _ => Err(Error::other(
format!("{collection} is not a collection"),
)),
}?;
@@ -195,7 +193,7 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
while !remaining_template.is_empty() && remaining_template.contains("{{") {
let directive_start_index = remaining_template
.find("{{")
- .ok_or_else(|| Error::new(Other, "Was expecting at least one tag opener"))?;
+ .ok_or_else(|| Error::other("Was expecting at least one tag opener"))?;
if directive_start_index > 0 {
let text = remaining_template[..directive_start_index].to_string();
tokens.push(Token::Text(text.to_string()));
@@ -204,7 +202,7 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
let directive_end_index = remaining_template
.find("}}")
- .ok_or_else(|| Error::new(Other, "Was expecting }} after {{"))?
+ .ok_or_else(|| Error::other("Was expecting }} after {{"))?
+ 2;
let directive = &remaining_template[..directive_end_index];
remaining_template = &remaining_template[directive_end_index..];
@@ -225,8 +223,7 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
if directive_type == '?' {
let closing_block = remaining_template.find("{{?}}").ok_or_else(|| {
- Error::new(
- Other,
+ Error::other(
"Could not find closing tag, expecting {{?}}, found end-of-file",
)
})?;
@@ -240,8 +237,7 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
} else if directive_type == '~' {
let parts: Vec<_> = content.splitn(2, ':').collect();
let closing_block = remaining_template.find("{{~}}").ok_or_else(|| {
- Error::new(
- Other,
+ Error::other(
"Could not find closing tag, expecting {{?}}, found end-of-file",
)
})?;
@@ -264,8 +260,7 @@ fn tokenize(template: &str, tokens: &mut Vec<Token>) -> Result<()> {
}
}
_ => {
- return Err(Error::new(
- Other,
+ return Err(Error::other(
"{{ }} is not a valid directive. Need one of: =, ? or ~.",
));
}