Add list-pages command

This commit is contained in:
Joscha 2022-10-22 19:24:58 +02:00
parent c40153be9f
commit 0e3d61d632
3 changed files with 40 additions and 12 deletions

View file

@ -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;

View file

@ -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(())
}

View file

@ -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),
}
}