show category takes optional name argument

This way it follows logic of other subcommands.
This commit is contained in:
fiplox 2021-05-31 23:04:27 +02:00
parent 1e4fb62369
commit 803748d956
2 changed files with 22 additions and 22 deletions

View File

@ -92,8 +92,7 @@ pub fn make_app() -> App<'static, 'static> {
Arg::with_name("category")
.help("Show all notes from a category/date.")
.short("c")
.long("category")
.conflicts_with("name"),
.long("category"),
)
.arg(Arg::with_name("name").help("Name of the note.")),
)

View File

@ -112,27 +112,28 @@ pub fn search(matches: &ArgMatches) -> Result<()> {
/// Process argument `show`.
pub fn show(matches: &ArgMatches) -> Result<()> {
match matches.value_of("name") {
Some(s) => notes::show(s)?,
None => match matches.is_present("all") {
true => notes::show_all()?,
false => match matches.is_present("category") {
true => {
let category: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Name of category:")
.interact_text()?;
notes::show_category(&category)?;
}
false => {
let s: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("String to search")
.interact_text()?;
notes::show(&s)?;
}
},
},
if matches.is_present("all") {
return notes::show_all();
}
if matches.is_present("category") {
let category: String = match matches.value_of("name") {
Some(s) => s.to_string(),
None => Input::with_theme(&ColorfulTheme::default())
.with_prompt("Category:")
.interact_text()?,
};
return notes::show_category(&category);
}
match matches.value_of("name") {
Some(s) => return notes::show(s),
None => {
let s: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("String to search")
.interact_text()?;
return notes::show(&s);
}
}
Ok(())
}
/// Process argument `panic`.