add possibility to add and edit links in tasks
This commit is contained in:
parent
bd0ea82f8e
commit
80c5265e3b
2 changed files with 42 additions and 8 deletions
23
src/cli.rs
23
src/cli.rs
|
@ -14,7 +14,24 @@ pub enum SubCommand {
|
||||||
Pause,
|
Pause,
|
||||||
Finish,
|
Finish,
|
||||||
Status,
|
Status,
|
||||||
Add { name: String },
|
Add {
|
||||||
Edit { idx: usize, name: String },
|
#[clap(short, long)]
|
||||||
Remove { idx: usize },
|
link: Option<String>,
|
||||||
|
|
||||||
|
name: String,
|
||||||
|
},
|
||||||
|
Edit {
|
||||||
|
#[clap(short, long)]
|
||||||
|
link: Option<String>,
|
||||||
|
#[clap(long)]
|
||||||
|
no_link: bool,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
name: Option<String>,
|
||||||
|
|
||||||
|
idx: usize,
|
||||||
|
},
|
||||||
|
Remove {
|
||||||
|
idx: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -16,10 +16,10 @@ fn main() {
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
cli::SubCommand::Add { name } => {
|
cli::SubCommand::Add { link, name } => {
|
||||||
tasks.push(Task {
|
tasks.push(Task {
|
||||||
name,
|
name,
|
||||||
link: None,
|
link,
|
||||||
description: None,
|
description: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,12 +29,25 @@ fn main() {
|
||||||
|
|
||||||
println!("added");
|
println!("added");
|
||||||
}
|
}
|
||||||
cli::SubCommand::Edit { idx, name } => {
|
cli::SubCommand::Edit {
|
||||||
|
idx,
|
||||||
|
name,
|
||||||
|
link,
|
||||||
|
no_link,
|
||||||
|
} => {
|
||||||
if idx == 0 || idx > tasks.len() {
|
if idx == 0 || idx > tasks.len() {
|
||||||
println!("invalid index");
|
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();
|
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
|
||||||
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
||||||
|
@ -74,7 +87,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
cli::SubCommand::List => {
|
cli::SubCommand::List => {
|
||||||
for (i, task) in tasks.iter().enumerate() {
|
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 => {
|
cli::SubCommand::Start => {
|
||||||
|
|
Loading…
Reference in a new issue