diff --git a/brood/src/commands.rs b/brood/src/commands.rs index 5e71884..4076f1c 100644 --- a/brood/src/commands.rs +++ b/brood/src/commands.rs @@ -1,7 +1,4 @@ -mod ingest; -mod path; -mod reexport; - -pub use ingest::ingest; -pub use path::path; -pub use reexport::reexport; +pub mod ingest; +pub mod list_pages; +pub mod path; +pub mod reexport; diff --git a/brood/src/commands/list_pages.rs b/brood/src/commands/list_pages.rs new file mode 100644 index 0000000..e80b6ee --- /dev/null +++ b/brood/src/commands/list_pages.rs @@ -0,0 +1,23 @@ +use std::fs::File; +use std::io::{self, BufReader}; +use std::path::Path; + +use crate::data::AdjacencyList; + +pub fn run(datafile: &Path) -> io::Result<()> { + let mut databuf = BufReader::new(File::open(datafile)?); + let data = AdjacencyList::read(&mut databuf)?; + + for (page_idx, page) in data.pages.iter().enumerate() { + if page.data.redirect { + for link_idx in data.link_range(page_idx as u32) { + let target_page = data.page(data.link(link_idx).to); + println!("{:?} -> {:?}", page.data.title, target_page.data.title); + } + } else { + println!("{:?}", page.data.title); + } + } + + Ok(()) +} diff --git a/brood/src/main.rs b/brood/src/main.rs index dec36d5..06fa4ce 100644 --- a/brood/src/main.rs +++ b/brood/src/main.rs @@ -12,9 +12,16 @@ enum Command { /// Read sift data on stdin and output brood data. Ingest, /// Read and reexport brood data. - Reexport { to: PathBuf }, + Reexport { + to: PathBuf, + }, /// Find a path from one article to another. - Path { from: String, to: String }, + Path { + from: String, + to: String, + }, + // Print all page titles. + ListPages, } #[derive(Debug, Parser)] @@ -27,8 +34,9 @@ struct Args { fn main() -> io::Result<()> { let args = Args::parse(); match args.command { - Command::Ingest => commands::ingest(&args.datafile), - Command::Reexport { to } => commands::reexport(&args.datafile, &to), - Command::Path { from, to } => commands::path(&args.datafile, &from, &to), + Command::Ingest => commands::ingest::ingest(&args.datafile), + Command::Reexport { to } => commands::reexport::reexport(&args.datafile, &to), + Command::Path { from, to } => commands::path::path(&args.datafile, &from, &to), + Command::ListPages => commands::list_pages::run(&args.datafile), } }