Skip to content

Commit

Permalink
Merge branch 'canary' into wf/tidy_and_add_lint_jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Shigure Kurosaki <[email protected]>
  • Loading branch information
kurosakishigure authored Jan 11, 2025
2 parents 7c6e5d9 + ed09749 commit 6bf639b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ Session.vim
\#*
\#*\#
.#*
tmp/**
!tmp/.gitkeep

# Before adding new lines, see the comment at the top.
74 changes: 12 additions & 62 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
[dependencies]
anyhow = "1.0.95"
chrono = "0.4.39"
clap = { version = "4.5.24", features = ["derive", "env"] }
clap = { version = "4.5.26", features = ["derive", "env"] }
glob = "0.3.2"
inquire = "0.7.5"
rss = "2.0.11"
Expand All @@ -38,9 +38,10 @@ tokio = { version = "1.42.0", features = [
"macros",
"rt-multi-thread",
] }
thiserror = "2.0.11"
tokio = { version = "1.43.0", features = ["fs", "io-util", "macros", "rt-multi-thread"] }
toml = "0.8.19"
url = { version = "2.5.4", features = ["serde"] }

[dev-dependencies]
tokio-test = "0.4.4"
tempfile = "3.15.0"
16 changes: 6 additions & 10 deletions src/arg/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,16 @@ pub async fn builder(config_path: &PathBuf) -> Result<Channel, Errors> {
});
}

if rss.output.as_os_str().is_empty() {
Ok(channel_builder(rss, items))
} else {
println!("- create: {}", rss.output.to_string_lossy());
println!("- create: {}", rss.output.to_string_lossy());

let mut rss_file = File::create(&rss.output).await?;
let channel = channel_builder(rss, items);
let mut rss_file = File::create(&rss.output).await?;
let channel = channel_builder(rss, items);

rss_file.write_all(channel.to_string().as_ref()).await?;
rss_file.write_all(channel.to_string().as_ref()).await?;

Ok(channel)
}
Ok(channel)
} else {
eprintln!("- {}", config_path.to_string_lossy());
eprintln!("- config: {}", config_path.to_string_lossy());

Err(Errors::FileNotExistError)
}
Expand Down
19 changes: 5 additions & 14 deletions src/cmd/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@ use crate::error::app::Errors;
use anyhow::Result;
use inquire::Select;
use std::path::PathBuf;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;

async fn create_config_file(path: &PathBuf) -> Result<(), Errors> {
let mut config_file = File::create(path).await?;

config_file
.write_all(include_bytes!("katharsis.config.toml"))
.await?;

Ok(())
}
use tokio::fs;

/// Generate a config file.
///
Expand Down Expand Up @@ -41,15 +30,17 @@ async fn create_config_file(path: &PathBuf) -> Result<(), Errors> {
/// - When the options cannot be displayed.
/// - When the file cannot be written to.
pub async fn init(path: &PathBuf) -> Result<(), Errors> {
let config_bytes = include_bytes!("katharsis.config.toml");

if path.try_exists()? {
let options: Vec<&str> = vec!["Yes", "No"];
let ans: &str = Select::new("A katharsis.config.toml already exists in the current directory. Do you want to overwrite it?", options).prompt()?;

if ans == "yes" {
create_config_file(path).await?;
fs::write(path, config_bytes).await?;
}
} else {
create_config_file(path).await?;
fs::write(path, config_bytes).await?;
}

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions tests/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use chrono::DateTime;
use katharsis::arg;
use rss::{Enclosure, Guid, Image};
use std::path::PathBuf;
use tokio::fs;
use tokio_test::assert_ok;

#[tokio::test]
Expand Down Expand Up @@ -67,4 +68,6 @@ async fn builder() {
} else {
panic!("lastBuildDate not found")
}

assert_ok!(fs::remove_file(PathBuf::from("tmp/rss.xml")).await);
}
8 changes: 5 additions & 3 deletions tests/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use katharsis::cmd;
use serde::Deserialize;
use std::path::PathBuf;
use tokio::fs;
use tokio_test::assert_ok;

Expand Down Expand Up @@ -41,12 +42,11 @@ struct Config {

#[tokio::test]
async fn init() {
let temp_dir = tempfile::tempdir().expect("failed to create temporary folder");
let path = temp_dir.path().join("katharsis.config.toml");
let path = PathBuf::from("tmp/katharsis.config.toml");

assert_ok!(cmd::handle::init(&path).await);

let content = assert_ok!(fs::read_to_string(path).await);
let content = assert_ok!(fs::read_to_string(&path).await);
let config: Config = assert_ok!(toml::from_str(&content));
let Config { rss, article } = config;

Expand All @@ -67,4 +67,6 @@ async fn init() {
assert_eq!(article.date, "time");
assert_eq!(article.image, "articles/**/image.png");
assert!(article.sort);

assert_ok!(fs::remove_file(path).await);
}
2 changes: 1 addition & 1 deletion tests/katharsis.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ site_url = "https://nextjs.org"
image = "favicon.png"
copyright = "© 2024 Vercel Inc"
language = "en"
output = ""
output = "tmp/rss.xml"

[article]
title = "h1"
Expand Down
Empty file added tmp/.gitkeep
Empty file.

0 comments on commit 6bf639b

Please sign in to comment.