Skip to content

Commit

Permalink
add title option to new subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 6, 2020
1 parent e326955 commit 563329c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/command/new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::create_new_file;

pub fn new() -> Result<(), Box<dyn std::error::Error>> {
let new = create_new_file("# ")?;
pub fn new(title: Option<&str>) -> Result<(), Box<dyn std::error::Error>> {
let new = create_new_file(&format!("# {}", title.unwrap_or("")))?;
println!("{}", new);
Ok(())
}
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.help("Prints obsoleted memo titles"),
),
)
.subcommand(clap::SubCommand::with_name("new").about("Creates a new memo"))
.subcommand(
clap::SubCommand::with_name("new")
.about("Creates a new memo")
.arg(
clap::Arg::with_name("title")
.long("title")
.value_name("TITLE")
.help("Creates a new memo with the specified title"),
),
)
.subcommand(clap::SubCommand::with_name("server").about("Runs server"))
.get_matches();
match matches.subcommand() {
("new", _) => crate::command::new::new()?,
("new", Some(sub_matches)) => {
let title = sub_matches.value_of("title");
crate::command::new::new(title)?
}
("edit", Some(sub_matches)) => {
let id_like_string = sub_matches.value_of("IDLike").expect("IDLike required");
crate::command::edit::edit(id_like_string)?
Expand Down

0 comments on commit 563329c

Please sign in to comment.