use std::io;
use std::path::PathBuf;
use fst::Streamer;
use crate::errors;
#[derive(Debug, StructOpt)]
#[structopt(verbatim_doc_comment)]
#[allow(clippy::tabs_in_doc_comments)]
pub struct PrintIndex {
#[structopt(parse(from_os_str))]
pub fst_file: PathBuf,
}
pub fn printindex(args: PrintIndex) -> errors::Result<()> {
let mut writer = csv::WriterBuilder::new()
.delimiter(b'\t')
.from_writer(io::stdout());
let index = unsafe { fst::Map::from_path(args.fst_file) }?;
let mut stream = index.stream();
while let Some((k, v)) = stream.next() {
writer.serialize((String::from_utf8_lossy(k), v))?;
}
Ok(())
}