update
This commit is contained in:
parent
e0e9c3e4a0
commit
823319dd02
3 changed files with 59 additions and 58 deletions
|
@ -114,7 +114,7 @@ pub fn get_args() -> Args {
|
|||
fn get_args_match() -> ArgMatches {
|
||||
command!()
|
||||
.about("Query markdown files")
|
||||
.arg(arg!([dir] "Directory to scan").required(true))
|
||||
.arg(arg!([dir] "Directory to scan").required(false).default_value("."))
|
||||
.arg(arg!(-j --json "Output result as JSON").required(false))
|
||||
.arg(
|
||||
arg!(-l --limit <LIMIT> "Limit number of results returned")
|
||||
|
|
|
@ -167,6 +167,7 @@ impl Index {
|
|||
if e.path().extension().is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if e.path().extension().unwrap().to_str().unwrap() == "md" {
|
||||
let path = e.path().to_str().unwrap().to_owned();
|
||||
let content = std::fs::read_to_string(&path).unwrap();
|
||||
|
@ -270,14 +271,14 @@ impl Index {
|
|||
|
||||
for doc in self.documents.clone() {
|
||||
grouped_items
|
||||
.entry(stringify(&serde_yaml::to_value(&doc.get_key(key)).unwrap()))
|
||||
.entry(stringify(&serde_yaml::to_value(doc.get_key(key)).unwrap()))
|
||||
.or_default()
|
||||
.push(doc);
|
||||
}
|
||||
|
||||
grouped_items
|
||||
.into_iter()
|
||||
.map(|(key, item)| (key, Index { documents: item }))
|
||||
.map(|(key, item)| (key, Self { documents: item }))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -302,7 +303,7 @@ impl Index {
|
|||
for doc in &self.documents {
|
||||
let mut rcol = vec![];
|
||||
for c in col {
|
||||
rcol.push(stringify(&serde_yaml::to_value(&doc.get_key(c)).unwrap()));
|
||||
rcol.push(stringify(&serde_yaml::to_value(doc.get_key(c)).unwrap()));
|
||||
}
|
||||
rows.push(rcol);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue