show all notes from a category
This commit is contained in:
parent
12d9b54ea2
commit
6d3a932b54
@ -66,6 +66,14 @@ pub fn make_app() -> App<'static, 'static> {
|
|||||||
.short("a")
|
.short("a")
|
||||||
.long("all"),
|
.long("all"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("category")
|
||||||
|
.help("Show all notes from a category/date")
|
||||||
|
.short("c")
|
||||||
|
.short("d")
|
||||||
|
.long("category")
|
||||||
|
.long("date"),
|
||||||
|
)
|
||||||
.arg(Arg::with_name("header").help("Name of the note.")),
|
.arg(Arg::with_name("header").help("Name of the note.")),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -190,3 +190,37 @@ pub fn show_all() -> Result<()> {
|
|||||||
show::run_app(skin, md)?;
|
show::run_app(skin, md)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show(header: &str) -> Result<()> {
|
||||||
|
let path = find_path(header)?;
|
||||||
|
match path {
|
||||||
|
Some(s) => {
|
||||||
|
let skin = show::make_skin();
|
||||||
|
let content = fs::read_to_string(s)?;
|
||||||
|
show::run_app(skin, &content)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
None => Err(anyhow!("Abort.")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_category(category: &str) -> Result<()> {
|
||||||
|
let base = get_base_path()?;
|
||||||
|
let path = format!("{}{}", base, category);
|
||||||
|
let mut files: Vec<String> = Vec::new();
|
||||||
|
if std::path::Path::new(&path).exists() {
|
||||||
|
for (_, file) in WalkDir::new(path)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|file| file.ok())
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
if file.metadata()?.is_file() {
|
||||||
|
files.push(fs::read_to_string(file.path())?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let skin = show::make_skin();
|
||||||
|
let md = &files.join("---\n");
|
||||||
|
show::run_app(skin, md)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -70,11 +70,19 @@ pub fn search(matches: &ArgMatches) -> Result<()> {
|
|||||||
|
|
||||||
pub fn show(matches: &ArgMatches) -> Result<()> {
|
pub fn show(matches: &ArgMatches) -> Result<()> {
|
||||||
match matches.value_of("header") {
|
match matches.value_of("header") {
|
||||||
Some(s) => unimplemented!("{}", s),
|
Some(s) => notes::show(s)?,
|
||||||
None => match matches.is_present("all") {
|
None => match matches.is_present("all") {
|
||||||
true => notes::show_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 => return Err(anyhow!("No option is given. Abort.")),
|
false => return Err(anyhow!("No option is given. Abort.")),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user