diff --git a/src/cli.rs b/src/cli.rs index a9b85d8..245c7fe 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,7 +14,24 @@ pub enum SubCommand { Pause, Finish, Status, - Add { name: String }, - Edit { idx: usize, name: String }, - Remove { idx: usize }, + Add { + #[clap(short, long)] + link: Option, + + name: String, + }, + Edit { + #[clap(short, long)] + link: Option, + #[clap(long)] + no_link: bool, + + #[clap(short, long)] + name: Option, + + idx: usize, + }, + Remove { + idx: usize, + }, } diff --git a/src/main.rs b/src/main.rs index 8eeb4fd..4c1173b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,10 @@ fn main() { .unwrap_or_default(); match args.command { - cli::SubCommand::Add { name } => { + cli::SubCommand::Add { link, name } => { tasks.push(Task { name, - link: None, + link, description: None, }); @@ -29,12 +29,25 @@ fn main() { println!("added"); } - cli::SubCommand::Edit { idx, name } => { + cli::SubCommand::Edit { + idx, + name, + link, + no_link, + } => { if idx == 0 || idx > tasks.len() { println!("invalid index"); } - tasks[idx - 1].name = name; + let mut task = &mut tasks[idx - 1]; + if let Some(name) = name { + task.name = name; + } + if let Some(link) = link { + task.link = Some(link); + } else if no_link { + task.link = None; + } let mut file = std::fs::File::create(&tasks_file_path).unwrap(); file.write_all(&serde_json::to_vec(&tasks).unwrap()) @@ -74,7 +87,11 @@ fn main() { } cli::SubCommand::List => { for (i, task) in tasks.iter().enumerate() { - println!("{}. {}", i + 1, task.name); + print!("{}. ", i + 1); + if task.link.is_some() { + print!("(link) "); + } + println!("{}", task.name); } } cli::SubCommand::Start => {