//! Copyright (C) 2022, Dmitriy Pleshevskiy //! //! 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 . //! //--------------------------------------------------------------------- // Rustc lints #![deny( unused_imports, unused_qualifications, rust_2018_idioms, unsafe_code, non_ascii_idents )] // Clippy lints #![deny(clippy::all)] //--------------------------------------------------------------------- use clap::Parser; use repo::fs::FsRepo; use serde::{Deserialize, Serialize}; use xdg::BaseDirectories; mod cli; pub mod domain; pub mod repo; fn main() { let args = cli::Args::parse(); let xdg_dirs = BaseDirectories::with_prefix(env!("CARGO_PKG_NAME")).unwrap(); let repo = FsRepo::new(xdg_dirs); let finished_tasks_file_path = xdg_dirs.place_data_file("finished_data.json").unwrap(); let current_task_info_file_path = xdg_dirs.place_data_file("current.json").unwrap(); let current_task_info: Option = 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(repo, args); } cli::SubCommand::Edit(args) => { cli::edit::execute( repo, cli::edit::Request { args, current_task_info, }, ); } 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)] pub struct CurrentTaskInfo { task_idx: usize, task: Task, // started_at }