From 66c950f6ab203fa877679806b546ee5cfbf0b07b Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 18 Aug 2022 11:37:52 +0300 Subject: [PATCH 1/2] cli: rename the status subcommand to show add missed licence headers --- src/cli.rs | 7 ++++--- src/cli/add.rs | 15 +++++++++++++++ src/cli/edit.rs | 15 +++++++++++++++ src/cli/finish.rs | 15 +++++++++++++++ src/cli/list.rs | 15 +++++++++++++++ src/cli/pause.rs | 15 +++++++++++++++ src/cli/priority.rs | 15 +++++++++++++++ src/cli/remove.rs | 15 +++++++++++++++ src/cli/{status.rs => show.rs} | 15 +++++++++++++++ src/cli/start.rs | 15 +++++++++++++++ src/domain.rs | 15 +++++++++++++++ src/main.rs | 4 ++-- src/repo.rs | 15 +++++++++++++++ src/repo/fs.rs | 15 +++++++++++++++ 14 files changed, 186 insertions(+), 5 deletions(-) rename src/cli/{status.rs => show.rs} (55%) 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/status.rs b/src/cli/show.rs similarity index 55% rename from src/cli/status.rs rename to src/cli/show.rs index 467ba6a..17c2046 100644 --- a/src/cli/status.rs +++ b/src/cli/show.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::domain::CurrentTaskInfo; use crate::repo::Repository; 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/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; -- 2.46.1 From ced77f9aa2b9020ff0e7ad24b3d6e756bfb2d46b Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Thu, 18 Aug 2022 11:54:23 +0300 Subject: [PATCH 2/2] cli/show: add possibility to print path and link --- src/cli/show.rs | 51 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/cli/show.rs b/src/cli/show.rs index 17c2046..2e367af 100644 --- a/src/cli/show.rs +++ b/src/cli/show.rs @@ -19,8 +19,25 @@ use crate::repo::Repository; #[derive(clap::Args)] pub struct Args { - #[clap(long)] - print_path: bool, + 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) { @@ -34,15 +51,25 @@ pub fn execute(repo: impl Repository, args: Args) { } }; - 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); + 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") + } + } } } -- 2.46.1