Skip to content

Commit

Permalink
add link subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 19, 2020
1 parent cbf5efb commit 826495c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/command/link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::page_id::PageId;
use crate::page_title::PageTitle;
use crate::url_helpers::{page_url, title_url};

pub fn link(id_like_or_title: &str) -> Result<(), Box<dyn std::error::Error>> {
let url = match PageId::from_like_str(id_like_or_title) {
Some(page_id) => page_url(&page_id),
None => {
let page_title = PageTitle::from_str(id_like_or_title);
title_url(&page_title)
}
};
println!("[{}]({})", id_like_or_title, url);
Ok(())
}
1 change: 1 addition & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod edit;
pub mod link;
pub mod list;
pub mod list_title;
pub mod new;
Expand Down
15 changes: 15 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.required(true),
),
)
.subcommand(
clap::SubCommand::with_name("link")
.about("Shows a link for memo")
.arg(
clap::Arg::with_name("ID_LIKE_OR_TITLE")
.help("the id or title of the memo")
.required(true),
),
)
.subcommand(
clap::SubCommand::with_name("list")
.about("Lists memos")
Expand Down Expand Up @@ -58,6 +67,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let id_like_string = sub_matches.value_of("IDLike").expect("IDLike required");
crate::command::edit::edit(id_like_string)?
}
("link", Some(sub_matches)) => {
let id_like_or_title_string = sub_matches
.value_of("ID_LIKE_OR_TITLE")
.expect("ID or TITLE required");
crate::command::link::link(id_like_or_title_string)?
}
("list", Some(sub_matches)) => {
let obsoleted = sub_matches.is_present("obsoleted");
crate::command::list::list(obsoleted)?
Expand Down

0 comments on commit 826495c

Please sign in to comment.