add pause, finish and status subcommands
This commit is contained in:
parent
92e4ae4dc2
commit
e16011950d
1 changed files with 56 additions and 26 deletions
76
src/main.rs
76
src/main.rs
|
@ -13,6 +13,8 @@ fn main() {
|
||||||
|
|
||||||
let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap();
|
let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
|
|
||||||
|
let finished_tasks_file_path = xdg_dirs.place_data_file("finished_data.json").unwrap();
|
||||||
|
|
||||||
let tasks_file_path = xdg_dirs.place_data_file("data.json").unwrap();
|
let tasks_file_path = xdg_dirs.place_data_file("data.json").unwrap();
|
||||||
let mut tasks: Vec<Task> = std::fs::File::open(&tasks_file_path)
|
let mut tasks: Vec<Task> = std::fs::File::open(&tasks_file_path)
|
||||||
.map(|file| serde_json::from_reader(file).unwrap())
|
.map(|file| serde_json::from_reader(file).unwrap())
|
||||||
|
@ -41,7 +43,7 @@ fn main() {
|
||||||
no_link,
|
no_link,
|
||||||
} => {
|
} => {
|
||||||
if current_task_info.is_some() {
|
if current_task_info.is_some() {
|
||||||
panic!("You can change priority only when you don't have an active task, yet");
|
panic!("You can edit task only when you don't have an active task, yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx == 0 || idx > tasks.len() {
|
if idx == 0 || idx > tasks.len() {
|
||||||
|
@ -66,16 +68,20 @@ fn main() {
|
||||||
}
|
}
|
||||||
cli::SubCommand::Remove { idx } => {
|
cli::SubCommand::Remove { idx } => {
|
||||||
if current_task_info.is_some() {
|
if current_task_info.is_some() {
|
||||||
panic!("You can change priority only when you don't have an active task, yet");
|
panic!("You can remove task only when you don't have an active task, yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx == 0 || idx > tasks.len() {
|
if idx == 0 || idx > tasks.len() {
|
||||||
panic!("invalid index");
|
panic!("invalid index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let task = &tasks[idx - 1];
|
||||||
println!("You are deleting task:");
|
println!("You are deleting task:");
|
||||||
println!(" {}", tasks[idx - 1].name);
|
println!(" {}", task.name);
|
||||||
println!();
|
if let Some(ref link) = task.link {
|
||||||
|
println!(" link: {}", link);
|
||||||
|
}
|
||||||
|
|
||||||
println!("In most cases you need to `finish` command");
|
println!("In most cases you need to `finish` command");
|
||||||
loop {
|
loop {
|
||||||
print!("Do you still want to delete the task? (y/N): ");
|
print!("Do you still want to delete the task? (y/N): ");
|
||||||
|
@ -189,30 +195,54 @@ fn main() {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
cli::SubCommand::Pause => {
|
cli::SubCommand::Pause => {
|
||||||
println!("pausing...");
|
if current_task_info.take().is_none() {
|
||||||
|
panic!("You can use the pause subcommand only when you have an active task");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file = std::fs::File::create(¤t_task_info_file_path).unwrap();
|
||||||
|
file.write_all(&serde_json::to_vec(¤t_task_info).unwrap())
|
||||||
|
.unwrap();
|
||||||
println!("paused");
|
println!("paused");
|
||||||
}
|
}
|
||||||
cli::SubCommand::Finish => {
|
cli::SubCommand::Finish => match current_task_info.take() {
|
||||||
println!("finishing...");
|
None => {
|
||||||
println!("-- on finish hook found");
|
panic!("You can use the finish subcommand only when you have an active task")
|
||||||
println!("-- running...");
|
}
|
||||||
println!("> curl ...");
|
Some(info) => {
|
||||||
println!("-- status was changed to \"Deploy\" successfuly");
|
let mut finished_tasks: Vec<Task> = std::fs::File::open(&finished_tasks_file_path)
|
||||||
|
.map(|file| serde_json::from_reader(file).unwrap())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let task = tasks.remove(info.task_idx - 1);
|
||||||
|
finished_tasks.push(task);
|
||||||
|
|
||||||
|
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
|
||||||
|
file.write_all(&serde_json::to_vec(&tasks).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut file = std::fs::File::create(&finished_tasks_file_path).unwrap();
|
||||||
|
file.write_all(&serde_json::to_vec(&finished_tasks).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut file = std::fs::File::create(¤t_task_info_file_path).unwrap();
|
||||||
|
file.write_all(&serde_json::to_vec(¤t_task_info).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
println!("finished");
|
println!("finished");
|
||||||
}
|
}
|
||||||
cli::SubCommand::Status => {
|
},
|
||||||
println!("Information about your current task:");
|
cli::SubCommand::Status => match current_task_info {
|
||||||
println!("[work]");
|
None => {
|
||||||
println!("https://redmine.example.com/issues/4051");
|
panic!("You don't have an active task.");
|
||||||
println!(
|
|
||||||
"#4051 Plannig/Assignment: Assign week and day general delvirebles after regular"
|
|
||||||
);
|
|
||||||
println!("-------------------------------------------------------------------------");
|
|
||||||
println!("lorem impsum dolor dolor impsum lorem lorem impsum");
|
|
||||||
println!("lorem dolor impsum lorem lorem impsum");
|
|
||||||
println!("lorem dolor impsum lorem lorem impsum lorem impsum dolor dolor impsum lorem");
|
|
||||||
println!("lorem impsum");
|
|
||||||
}
|
}
|
||||||
|
Some(info) => {
|
||||||
|
println!("Information about your current task:");
|
||||||
|
println!(" {}", info.task.name);
|
||||||
|
if let Some(link) = info.task.link {
|
||||||
|
println!(" link: {}", link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue