diff --git a/.gitignore b/.gitignore index ea8c4bf..42fe5d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +/testfiles diff --git a/src/main.rs b/src/main.rs index e7a11a9..f5149f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,11 @@ -fn main() { - println!("Hello, world!"); +use tag::search::get_tags_from_files; + +fn main() -> Result<(), Box> { + let tagged_files = get_tags_from_files("testfiles")?; + + for file in tagged_files.iter() { + println!("File {} contains {:?}", file.path.display(), file.tags); + } + + Ok(()) } diff --git a/src/search.rs b/src/search.rs index 5254133..a8b643f 100644 --- a/src/search.rs +++ b/src/search.rs @@ -12,8 +12,8 @@ use crate::parsers::tagline::{self, TaglineParser}; /// TaggedFile is a file that contains tags. #[derive(Clone)] pub struct TaggedFile { - path: PathBuf, - tags: Vec, + pub path: PathBuf, + pub tags: Vec, } /// get_tags_from_file() returns a list of tags found in a file. @@ -24,14 +24,13 @@ fn get_tags_from_file(file: &Path) -> Result, Box tags.push(tag.as_str().to_string()), - _ => unreachable!(), + for tag in parsed { + if tag.as_rule() == tagline::Rule::tag { + tags.push(tag.as_str().to_string()) } } @@ -45,6 +44,11 @@ pub fn get_tags_from_files(directory: &str) -> Result, Box