//! 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 . //! use crate::{ cli::print_task_detail, repo::{self, Repository}, }; #[derive(clap::Args)] pub struct Args { #[clap(short, long)] project: Option, #[clap(short, long)] link: Option, #[clap(short, long = "dir")] dir_path: Option, name: String, } pub fn execute(repo: impl Repository, args: Args) { let res = repo.insert_task(repo::InsertTaskData { name: args.name, link: args.link, project: args.project, dir_path: args .dir_path .map(std::fs::canonicalize) .transpose() .unwrap(), index: None, }); match res { Ok(task) => { println!("The task was added successfully"); print_task_detail(&task); } Err(err) => { eprintln!("Cannot insert a new task: {}", err); } } }