get category name for "list" without prompt (from arg)

This commit is contained in:
fiplox 2021-05-31 20:53:07 +02:00
parent 56c4ed9011
commit beaa8a8119
2 changed files with 8 additions and 4 deletions

View File

@ -54,6 +54,7 @@ pub fn make_app() -> App<'static, 'static> {
.alias("l")
.alias("ls")
.about("List all notes or notes from a category.")
.arg(Arg::with_name("name").help("Name of the category."))
.arg(
Arg::with_name("category")
.help("List all notes from a category.")

View File

@ -69,10 +69,13 @@ pub fn edit(matches: &ArgMatches) -> Result<()> {
pub fn list(matches: &ArgMatches) -> Result<()> {
match matches.is_present("category") {
true => {
let s: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Category:")
.interact_text()?;
notes::list_category(&s)?;
let name: String = match matches.value_of("name") {
Some(s) => s.to_string(),
None => Input::with_theme(&ColorfulTheme::default())
.with_prompt("Category:")
.interact_text()?,
};
notes::list_category(&name)?;
}
false => notes::list_all_notes()?,
}