Merge pull request 'Show subcommand' (#24) from show into main

Reviewed-on: #24
This commit is contained in:
Dmitriy Pleshevskiy 2022-08-18 08:58:01 +00:00 committed by Gitea
commit 273d224e04
No known key found for this signature in database
GPG key ID: 55B75599806CD426
15 changed files with 246 additions and 38 deletions

View file

@ -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) {

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::{
cli::print_task_detail,
repo::{self, Repository},

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use std::path::PathBuf;
use crate::cli::print_task_detail;

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::cli::print_task_detail;
use crate::repo::{self, Repository};

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::domain::CurrentTaskInfo;
use crate::repo::Repository;

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::cli::print_task_detail;
use crate::repo::{self, Repository};

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::cli::print_task_detail;
use crate::repo::{self, Repository};

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::{
cli::print_task_detail,
repo::{self, Repository},

75
src/cli/show.rs Normal file
View file

@ -0,0 +1,75 @@
//! 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/>.
//!
use crate::cli::print_task_detail;
use crate::domain::CurrentTaskInfo;
use crate::repo::Repository;
#[derive(clap::Args)]
pub struct Args {
part: Option<PrintPart>,
}
#[derive(clap::ValueEnum, Clone)]
enum PrintPart {
Path,
Link,
}
impl std::str::FromStr for PrintPart {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
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")
}
}
}
}

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use crate::{
cli::print_task_detail,
repo::{self, Repository},

View file

@ -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);
}
}

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use std::path::PathBuf;
pub type TaskId = usize;

View file

@ -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);
}
}
}

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
pub mod fs;
use std::path::PathBuf;

View file

@ -1,3 +1,18 @@
//! 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/>.
//!
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;