refactor(codegen): Hard code data

This commit is contained in:
Ed Page 2019-10-28 10:09:29 -06:00
parent 1cbdb3a77a
commit 5de368ac9d
3 changed files with 8 additions and 11 deletions

1
Cargo.lock generated
View file

@ -804,6 +804,7 @@ dependencies = [
"phf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"typos-dict 0.1.1",
"unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

View file

@ -25,7 +25,7 @@ stages:
steps:
- template: azure/install-rust.yml@templates
- script: |
cargo run --package typos-codegen -- --input dict/typos/assets/words.csv --output dict/typos/src/dict_codegen.rs --check
cargo run --package typos-codegen -- --output dict/typos/src/dict_codegen.rs --check
displayName: Verify typos-dict
- script: |
cargo run --package codespell-codegen -- --output dict/codespell/src/dict_codegen.rs --check

View file

@ -1,6 +1,8 @@
use structopt::StructOpt;
fn generate<W: std::io::Write>(input: &[u8], file: &mut W) {
pub const DICT: &[u8] = include_bytes!("../../assets/words.csv");
fn generate<W: std::io::Write>(file: &mut W) {
writeln!(
file,
"// This file is code-genned by {}",
@ -16,7 +18,7 @@ fn generate<W: std::io::Write>(input: &[u8], file: &mut W) {
)
.unwrap();
let mut builder = phf_codegen::Map::new();
let records: Vec<_> = csv::Reader::from_reader(input)
let records: Vec<_> = csv::Reader::from_reader(DICT)
.records()
.map(|r| r.unwrap())
.collect();
@ -32,8 +34,6 @@ fn generate<W: std::io::Write>(input: &[u8], file: &mut W) {
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
struct Options {
#[structopt(long, parse(from_os_str))]
input: std::path::PathBuf,
#[structopt(flatten)]
codegen: codegenrs::CodeGenArgs,
#[structopt(flatten)]
@ -43,12 +43,8 @@ struct Options {
fn run() -> Result<i32, Box<dyn std::error::Error>> {
let options = Options::from_args();
let content = {
let mut content = vec![];
let input = std::fs::read(&options.input)?;
generate(&input, &mut content);
content
};
generate(&mut content);
let content = String::from_utf8(content)?;
let content = options.rustmft.reformat(&content)?;