133 lines
4 KiB
Rust
133 lines
4 KiB
Rust
//! Copyright (C) 2022, Dmitriy Pleshevskiy <dmitriy@ideascup.me>
|
|
//!
|
|
//! tas is free software: you can redistribute it and/or modify
|
|
//! it under the terms of the GNU General Public License as published by
|
|
//! the Free Software Foundation, either version 3 of the License, or
|
|
//! (at your option) any later version.
|
|
//!
|
|
//! tas is distributed in the hope that it will be useful,
|
|
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
//! GNU General Public License for more details.
|
|
//!
|
|
//! You should have received a copy of the GNU General Public License
|
|
//! along with tas. If not, see <https://www.gnu.org/licenses/>.
|
|
//!
|
|
//---------------------------------------------------------------------
|
|
// Rustc lints
|
|
#![deny(
|
|
unused_imports,
|
|
unused_qualifications,
|
|
rust_2018_idioms,
|
|
unsafe_code,
|
|
non_ascii_idents
|
|
)]
|
|
// Clippy lints
|
|
#![deny(clippy::all)]
|
|
//---------------------------------------------------------------------
|
|
|
|
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 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 mut tasks: Vec<Task> = std::fs::File::open(&tasks_file_path)
|
|
.map(|file| serde_json::from_reader(file).unwrap())
|
|
.unwrap_or_default();
|
|
|
|
let current_task_info_file_path = xdg_dirs.place_data_file("current.json").unwrap();
|
|
let current_task_info: Option<CurrentTaskInfo> =
|
|
std::fs::File::open(¤t_task_info_file_path)
|
|
.map(|file| serde_json::from_reader(file).unwrap())
|
|
.unwrap_or_default();
|
|
|
|
match args.command {
|
|
cli::SubCommand::Add(args) => {
|
|
cli::add::execute(cli::add::Request {
|
|
args,
|
|
tasks,
|
|
tasks_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::Edit(args) => {
|
|
cli::edit::execute(cli::edit::Request {
|
|
args,
|
|
current_task_info,
|
|
tasks,
|
|
tasks_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::Remove(args) => {
|
|
cli::remove::execute(cli::remove::Request {
|
|
args,
|
|
current_task_info,
|
|
tasks,
|
|
tasks_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::List => {
|
|
cli::list::execute(cli::list::Request {
|
|
tasks,
|
|
current_task_info,
|
|
});
|
|
}
|
|
cli::SubCommand::Priority(args) => {
|
|
cli::priority::execute(cli::priority::Request {
|
|
args,
|
|
tasks,
|
|
tasks_file_path,
|
|
current_task_info,
|
|
});
|
|
}
|
|
cli::SubCommand::Start(args) => {
|
|
cli::start::execute(cli::start::Request {
|
|
args,
|
|
tasks,
|
|
current_task_info,
|
|
current_task_info_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::Pause => {
|
|
cli::pause::execute(cli::pause::Request {
|
|
current_task_info,
|
|
current_task_info_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::Finish => {
|
|
cli::finish::execute(cli::finish::Request {
|
|
tasks,
|
|
current_task_info,
|
|
current_task_info_file_path,
|
|
tasks_file_path,
|
|
finished_tasks_file_path,
|
|
});
|
|
}
|
|
cli::SubCommand::Status => {
|
|
cli::status::execute(current_task_info);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone)]
|
|
pub struct Task {
|
|
name: String,
|
|
link: Option<String>,
|
|
// created_at
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub struct CurrentTaskInfo {
|
|
task_idx: usize,
|
|
task: Task,
|
|
// started_at
|
|
}
|