Skip to content

Commit

Permalink
bbn: add --web to view
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jul 7, 2021
1 parent ada436f commit 4da6d83
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
21 changes: 21 additions & 0 deletions bbn/Cargo.lock

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

1 change: 1 addition & 0 deletions bbn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ date-range = { path = "../date-range/" }
diff = "0.1.12"
hatena-blog = { git = "https://github.com/bouzuya/rust-hatena-blog", tag = "0.12.0" }
nom = "6.1.2"
open = "1.7.0"
serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
sqlx = { version = "0.5.5", features = [ "runtime-tokio-rustls", "sqlite" ] }
Expand Down
26 changes: 17 additions & 9 deletions bbn/src/command/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::bail;
use date_range::date::Date;
use std::path::PathBuf;

pub fn view(data_dir: PathBuf, date: Date) -> anyhow::Result<()> {
pub fn view(data_dir: PathBuf, date: Date, web: bool) -> anyhow::Result<()> {
let repository = BbnRepository::new(data_dir);
let entry_id = repository.find_id_by_date(date)?;
let entry_meta = entry_id
Expand All @@ -12,16 +12,24 @@ pub fn view(data_dir: PathBuf, date: Date) -> anyhow::Result<()> {
.transpose()?;
match (entry_id, entry_meta) {
(Some(entry_id), Some(entry_meta)) => {
println!(
"{}{} {} https://blog.bouzuya.net/{}/",
entry_id.date(),
entry_id
.id_title()
.map(|s| format!(" {}", s))
.unwrap_or_default(),
entry_meta.title,
let url = format!(
"https://blog.bouzuya.net/{}/",
entry_id.date().to_string().replace('-', "/")
);
if web {
open::that(url)?;
} else {
println!(
"{}{} {} {}",
entry_id.date(),
entry_id
.id_title()
.map(|s| format!(" {}", s))
.unwrap_or_default(),
entry_meta.title,
url
);
}
}
_ => bail!("not found"),
}
Expand Down
8 changes: 7 additions & 1 deletion bbn/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ enum Subcommand {
data_dir: PathBuf,
#[structopt(name = "date", help = "the date")]
date: Date,
#[structopt(long = "web", help = "Open the entry in the browser")]
web: bool,
},
}

Expand All @@ -74,6 +76,10 @@ async fn main() -> anyhow::Result<()> {
query,
} => command::list(data_dir, json, query),
Subcommand::HatenaBlog { subcommand } => command::hatena_blog(subcommand).await,
Subcommand::View { data_dir, date } => command::view(data_dir, date),
Subcommand::View {
data_dir,
date,
web,
} => command::view(data_dir, date, web),
}
}

0 comments on commit 4da6d83

Please sign in to comment.