Add list-pages command
This commit is contained in:
parent
c40153be9f
commit
0e3d61d632
3 changed files with 40 additions and 12 deletions
|
|
@ -1,7 +1,4 @@
|
||||||
mod ingest;
|
pub mod ingest;
|
||||||
mod path;
|
pub mod list_pages;
|
||||||
mod reexport;
|
pub mod path;
|
||||||
|
pub mod reexport;
|
||||||
pub use ingest::ingest;
|
|
||||||
pub use path::path;
|
|
||||||
pub use reexport::reexport;
|
|
||||||
|
|
|
||||||
23
brood/src/commands/list_pages.rs
Normal file
23
brood/src/commands/list_pages.rs
Normal 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(())
|
||||||
|
}
|
||||||
|
|
@ -12,9 +12,16 @@ enum Command {
|
||||||
/// Read sift data on stdin and output brood data.
|
/// Read sift data on stdin and output brood data.
|
||||||
Ingest,
|
Ingest,
|
||||||
/// Read and reexport brood data.
|
/// Read and reexport brood data.
|
||||||
Reexport { to: PathBuf },
|
Reexport {
|
||||||
|
to: PathBuf,
|
||||||
|
},
|
||||||
/// Find a path from one article to another.
|
/// 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)]
|
#[derive(Debug, Parser)]
|
||||||
|
|
@ -27,8 +34,9 @@ struct Args {
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
match args.command {
|
match args.command {
|
||||||
Command::Ingest => commands::ingest(&args.datafile),
|
Command::Ingest => commands::ingest::ingest(&args.datafile),
|
||||||
Command::Reexport { to } => commands::reexport(&args.datafile, &to),
|
Command::Reexport { to } => commands::reexport::reexport(&args.datafile, &to),
|
||||||
Command::Path { from, to } => commands::path(&args.datafile, &from, &to),
|
Command::Path { from, to } => commands::path::path(&args.datafile, &from, &to),
|
||||||
|
Command::ListPages => commands::list_pages::run(&args.datafile),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue