tas/src/main.rs

106 lines
3.4 KiB
Rust
Raw Normal View History

2022-08-05 00:08:27 +03:00
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::io::Write;
use xdg::BaseDirectories;
mod cli;
fn main() {
let args = cli::Args::parse();
let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).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)
.map(|file| serde_json::from_reader(file).unwrap())
.unwrap_or_default();
match args.command {
cli::SubCommand::Add { name } => {
tasks.push(Task {
name,
link: None,
description: None,
});
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
file.write_all(&serde_json::to_vec(&tasks).unwrap())
.unwrap();
println!("added");
}
cli::SubCommand::Edit { idx, name } => {
if idx == 0 || idx > tasks.len() {
println!("invalid index");
}
tasks[idx - 1].name = name;
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
file.write_all(&serde_json::to_vec(&tasks).unwrap())
.unwrap();
println!("changed");
}
cli::SubCommand::Remove { idx } => {
if idx == 0 || idx > tasks.len() {
println!("invalid index");
}
tasks.remove(idx - 1);
let mut file = std::fs::File::create(&tasks_file_path).unwrap();
file.write_all(&serde_json::to_vec(&tasks).unwrap())
.unwrap();
println!("removed");
}
cli::SubCommand::List => {
for (i, task) in tasks.iter().enumerate() {
println!("{}. {}", i + 1, task.name);
}
}
cli::SubCommand::Start => {
println!("starting...");
println!("-- on start hook found");
println!("-- running...");
println!("> curl ...");
println!("-- status was changed to \"In progress\" successfuly");
println!("started");
}
cli::SubCommand::Pause => {
println!("pausing...");
println!("paused");
}
cli::SubCommand::Finish => {
println!("finishing...");
println!("-- on finish hook found");
println!("-- running...");
println!("> curl ...");
println!("-- status was changed to \"Deploy\" successfuly");
println!("finished");
}
cli::SubCommand::Status => {
println!("Information about your current task:");
println!("[work]");
println!("https://redmine.example.com/issues/4051");
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");
}
}
}
#[derive(Deserialize, Serialize)]
struct Task {
name: String,
link: Option<String>,
description: Option<String>,
// created_at
}