Dmitriy Pleshevskiy
18004c24d0
- rename group to project - rename path to dir_path - cli/show: add project to the print part - cli/show: improve print part error message Closes #25
69 lines
2 KiB
Rust
69 lines
2 KiB
Rust
//! 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;
|
|
use crate::repo::{self, Repository};
|
|
|
|
#[derive(clap::Args)]
|
|
pub struct Args {
|
|
#[clap(short, long)]
|
|
name: Option<String>,
|
|
|
|
#[clap(short, long)]
|
|
project: Option<String>,
|
|
#[clap(long)]
|
|
no_project: bool,
|
|
|
|
#[clap(short, long)]
|
|
link: Option<String>,
|
|
#[clap(long)]
|
|
no_link: bool,
|
|
|
|
#[clap(short, long = "dir")]
|
|
dir_path: Option<PathBuf>,
|
|
#[clap(long = "no-dir")]
|
|
no_dir_path: bool,
|
|
|
|
idx: usize,
|
|
}
|
|
|
|
pub fn execute(repo: impl Repository, args: Args) {
|
|
let res = repo.update_task(
|
|
args.idx,
|
|
repo::UpdateTaskData {
|
|
name: args.name,
|
|
project: args
|
|
.no_project
|
|
.then(|| None)
|
|
.or_else(|| args.project.map(Some)),
|
|
link: args.no_link.then(|| None).or_else(|| args.link.map(Some)),
|
|
dir_path: args
|
|
.no_dir_path
|
|
.then(|| None)
|
|
.or_else(|| args.dir_path.map(std::fs::canonicalize).transpose().ok()),
|
|
},
|
|
);
|
|
match res {
|
|
Ok(task) => {
|
|
println!("The task was changed successfully");
|
|
print_task_detail(&task);
|
|
}
|
|
Err(err) => {
|
|
eprintln!("Cannot update the task: {}", err);
|
|
}
|
|
}
|
|
}
|