cli: move printing the task path to the status subcommand

cli: add visible aliases for remove, list, status
This commit is contained in:
Dmitriy Pleshevskiy 2022-08-17 09:14:42 +03:00
parent 238e4b0b03
commit 8f9d53ccb3
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
4 changed files with 32 additions and 26 deletions

View file

@ -37,14 +37,16 @@ pub struct Args {
pub enum SubCommand {
Add(self::add::Args),
Edit(self::edit::Args),
#[clap(visible_alias("rm"))]
Remove(self::remove::Args),
Priority(self::priority::Args),
#[clap(alias("ls"))]
#[clap(visible_alias("ls"))]
List,
Start(self::start::Args),
Pause,
Finish(self::finish::Args),
Status,
#[clap(visible_alias("st"))]
Status(self::status::Args),
}
pub fn print_task_detail(task: &domain::Task) {

View file

@ -8,9 +8,6 @@ pub struct Args {
#[clap(short, long)]
open: bool,
#[clap(long)]
print_path: bool,
idx: Option<usize>,
}
@ -21,17 +18,8 @@ pub fn execute(repo: impl Repository, args: Args) {
Err(err) => return eprintln!("Cannot start 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!("The task was started successfully");
print_task_detail(&task);
}
println!("The task was started successfully");
print_task_detail(&task);
if let (Some(link), true) = (task.link.as_ref(), args.open) {
log::debug!("opening link...");

View file

@ -1,17 +1,33 @@
use crate::cli::print_task_detail;
use crate::domain::CurrentTaskInfo;
use crate::repo::Repository;
pub fn execute(repo: impl Repository) {
match repo.get_current_task_opt() {
#[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) => {
eprintln!("You don't have an active task.");
}
Ok(Some(info)) => {
println!("Information about your current task:");
print_task_detail(&info.task);
return eprintln!("You don't have an active task.");
}
Ok(Some(CurrentTaskInfo { task, .. })) => task,
Err(err) => {
eprintln!("Cannot read current task: {}", 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

@ -65,8 +65,8 @@ fn main() {
cli::SubCommand::Finish(args) => {
cli::finish::execute(repo, args);
}
cli::SubCommand::Status => {
cli::status::execute(repo);
cli::SubCommand::Status(args) => {
cli::status::execute(repo, args);
}
}
}