From f09066e927fd01dea8a81c8144889d89d50eb5b1 Mon Sep 17 00:00:00 2001 From: bouzuya Date: Sun, 6 Sep 2020 10:37:30 +0900 Subject: [PATCH] add list-title subcommand --- src/command/list_title.rs | 11 +++++++++++ src/command/mod.rs | 1 + src/main.rs | 13 +++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/command/list_title.rs diff --git a/src/command/list_title.rs b/src/command/list_title.rs new file mode 100644 index 0000000..bde3cd1 --- /dev/null +++ b/src/command/list_title.rs @@ -0,0 +1,11 @@ +pub fn list_title(all: bool) -> Result<(), Box> { + let titles = crate::use_case::list_title::list_title(all)?; + for title in titles { + println!( + "{}\t{}", + title.title.to_string(), + if title.obsoleted { "(obsoleted)" } else { "" } + ); + } + Ok(()) +} diff --git a/src/command/mod.rs b/src/command/mod.rs index 30b946b..5c4328a 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,4 +1,5 @@ pub mod edit; pub mod list; +pub mod list_title; pub mod new; pub mod server; diff --git a/src/main.rs b/src/main.rs index 0e3c9a9..b90b2a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,15 @@ fn main() -> Result<(), Box> { .help("Prints obsoleted memos"), ), ) + .subcommand( + clap::SubCommand::with_name("list-title") + .about("Lists memo titles") + .arg( + clap::Arg::with_name("obsoleted") + .long("obsoleted") + .help("Prints obsoleted memo titles"), + ), + ) .subcommand(clap::SubCommand::with_name("new").about("Creates a new memo")) .subcommand(clap::SubCommand::with_name("server").about("Runs server")) .get_matches(); @@ -41,6 +50,10 @@ fn main() -> Result<(), Box> { let obsoleted = sub_matches.is_present("obsoleted"); crate::command::list::list(obsoleted)? } + ("list-title", Some(sub_matches)) => { + let obsoleted = sub_matches.is_present("obsoleted"); + crate::command::list_title::list_title(obsoleted)? + } ("server", _) => crate::command::server::server()?, _ => {} }