Show subcommand #24
1 changed files with 39 additions and 12 deletions
|
@ -19,8 +19,25 @@ use crate::repo::Repository;
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[clap(long)]
|
part: Option<PrintPart>,
|
||||||
print_path: bool,
|
}
|
||||||
|
|
||||||
|
#[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) {
|
pub fn execute(repo: impl Repository, args: Args) {
|
||||||
|
@ -34,15 +51,25 @@ pub fn execute(repo: impl Repository, args: Args) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if args.print_path {
|
match args.part {
|
||||||
println!(
|
None => {
|
||||||
"{}",
|
println!("Information about your current task:");
|
||||||
task.path
|
print_task_detail(&task);
|
||||||
.unwrap_or_else(|| std::env::current_dir().expect("Cannot get current dir"))
|
}
|
||||||
.to_string_lossy()
|
Some(PrintPart::Path) => {
|
||||||
)
|
println!(
|
||||||
} else {
|
"{}",
|
||||||
println!("Information about your current task:");
|
task.path
|
||||||
print_task_detail(&task);
|
.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")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue