diff --git a/src/cli.rs b/src/cli.rs index d38d2d7..507f3e4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,8 +23,8 @@ pub mod list; pub mod pause; pub mod priority; pub mod remove; +pub mod show; pub mod start; -pub mod status; #[derive(clap::Parser)] #[clap(author, version, about = "Experemental task manager")] @@ -42,11 +42,12 @@ pub enum SubCommand { Priority(self::priority::Args), #[clap(visible_alias("ls"))] List, + #[clap(visible_alias("st"))] Start(self::start::Args), Pause, Finish(self::finish::Args), - #[clap(visible_alias("st"))] - Status(self::status::Args), + #[clap(visible_alias("sh"))] + Show(self::show::Args), } pub fn print_task_detail(task: &domain::Task) { diff --git a/src/cli/add.rs b/src/cli/add.rs index e8d6624..a210a5b 100644 --- a/src/cli/add.rs +++ b/src/cli/add.rs @@ -1,3 +1,18 @@ +//! 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}, diff --git a/src/cli/edit.rs b/src/cli/edit.rs index 3f0fa28..22e8527 100644 --- a/src/cli/edit.rs +++ b/src/cli/edit.rs @@ -1,3 +1,18 @@ +//! 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 std::path::PathBuf; use crate::cli::print_task_detail; diff --git a/src/cli/finish.rs b/src/cli/finish.rs index a0f25f4..8d8b6af 100644 --- a/src/cli/finish.rs +++ b/src/cli/finish.rs @@ -1,3 +1,18 @@ +//! 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; use crate::repo::{self, Repository}; diff --git a/src/cli/list.rs b/src/cli/list.rs index 187c9c2..0da8534 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -1,3 +1,18 @@ +//! 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::domain::CurrentTaskInfo; use crate::repo::Repository; diff --git a/src/cli/pause.rs b/src/cli/pause.rs index 7f47e09..a780364 100644 --- a/src/cli/pause.rs +++ b/src/cli/pause.rs @@ -1,3 +1,18 @@ +//! 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; use crate::repo::{self, Repository}; diff --git a/src/cli/priority.rs b/src/cli/priority.rs index f2525c1..dd2c4a0 100644 --- a/src/cli/priority.rs +++ b/src/cli/priority.rs @@ -1,3 +1,18 @@ +//! 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; use crate::repo::{self, Repository}; diff --git a/src/cli/remove.rs b/src/cli/remove.rs index 35d994d..83b38a7 100644 --- a/src/cli/remove.rs +++ b/src/cli/remove.rs @@ -1,3 +1,18 @@ +//! 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}, diff --git a/src/cli/show.rs b/src/cli/show.rs new file mode 100644 index 0000000..2e367af --- /dev/null +++ b/src/cli/show.rs @@ -0,0 +1,75 @@ +//! 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; +use crate::domain::CurrentTaskInfo; +use crate::repo::Repository; + +#[derive(clap::Args)] +pub struct Args { + part: Option, +} + +#[derive(clap::ValueEnum, Clone)] +enum PrintPart { + Path, + Link, +} + +impl std::str::FromStr for PrintPart { + type Err = &'static str; + + fn from_str(s: &str) -> Result { + match s { + "path" => Ok(PrintPart::Path), + "link" => Ok(PrintPart::Link), + _ => Err(r#"You can display only "path" or "link""#), + } + } +} + +pub fn execute(repo: impl Repository, args: Args) { + let task = match repo.get_current_task_opt() { + Ok(None) => { + return eprintln!("You don't have an active task."); + } + Ok(Some(CurrentTaskInfo { task, .. })) => task, + Err(err) => { + return eprintln!("Cannot read current task: {}", err); + } + }; + + match args.part { + None => { + println!("Information about your current task:"); + print_task_detail(&task); + } + Some(PrintPart::Path) => { + println!( + "{}", + task.path + .unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir")) + .to_string_lossy() + ) + } + Some(PrintPart::Link) => { + if let Some(link) = task.link { + println!("{}", link) + } else { + eprintln!("The current task doesn't contain link") + } + } + } +} diff --git a/src/cli/start.rs b/src/cli/start.rs index 966c14d..aa49f54 100644 --- a/src/cli/start.rs +++ b/src/cli/start.rs @@ -1,3 +1,18 @@ +//! 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}, diff --git a/src/cli/status.rs b/src/cli/status.rs deleted file mode 100644 index 467ba6a..0000000 --- a/src/cli/status.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::cli::print_task_detail; -use crate::domain::CurrentTaskInfo; -use crate::repo::Repository; - -#[derive(clap::Args)] -pub struct Args { - #[clap(long)] - print_path: bool, -} - -pub fn execute(repo: impl Repository, args: Args) { - let task = match repo.get_current_task_opt() { - Ok(None) => { - return eprintln!("You don't have an active task."); - } - Ok(Some(CurrentTaskInfo { task, .. })) => task, - Err(err) => { - return eprintln!("Cannot read current task: {}", err); - } - }; - - if args.print_path { - println!( - "{}", - task.path - .unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir")) - .to_string_lossy() - ) - } else { - println!("Information about your current task:"); - print_task_detail(&task); - } -} diff --git a/src/domain.rs b/src/domain.rs index e214d61..4c7bfd7 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -1,3 +1,18 @@ +//! 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 std::path::PathBuf; pub type TaskId = usize; diff --git a/src/main.rs b/src/main.rs index 77f8903..df93cb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,8 +65,8 @@ fn main() { cli::SubCommand::Finish(args) => { cli::finish::execute(repo, args); } - cli::SubCommand::Status(args) => { - cli::status::execute(repo, args); + cli::SubCommand::Show(args) => { + cli::show::execute(repo, args); } } } diff --git a/src/repo.rs b/src/repo.rs index 0eae031..081496f 100755 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,3 +1,18 @@ +//! 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 . +//! pub mod fs; use std::path::PathBuf; diff --git a/src/repo/fs.rs b/src/repo/fs.rs index 6e68cfa..5e0bfa2 100644 --- a/src/repo/fs.rs +++ b/src/repo/fs.rs @@ -1,3 +1,18 @@ +//! 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 std::fs::File; use std::io::Write; use std::path::PathBuf;