From 5de368ac9d5080a9b515a67f73f21c176ee008bd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 28 Oct 2019 10:09:29 -0600 Subject: [PATCH] refactor(codegen): Hard code data --- Cargo.lock | 1 + azure-pipelines.yml | 2 +- dict/typos/codegen/src/main.rs | 16 ++++++---------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f9ed84..e7f74b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6f0b0a8..db7f746 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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 diff --git a/dict/typos/codegen/src/main.rs b/dict/typos/codegen/src/main.rs index 8662447..de08268 100644 --- a/dict/typos/codegen/src/main.rs +++ b/dict/typos/codegen/src/main.rs @@ -1,6 +1,8 @@ use structopt::StructOpt; -fn generate(input: &[u8], file: &mut W) { +pub const DICT: &[u8] = include_bytes!("../../assets/words.csv"); + +fn generate(file: &mut W) { writeln!( file, "// This file is code-genned by {}", @@ -16,7 +18,7 @@ fn generate(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(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> { let options = Options::from_args(); - let content = { - let mut content = vec![]; - let input = std::fs::read(&options.input)?; - generate(&input, &mut content); - content - }; + let mut content = vec![]; + generate(&mut content); let content = String::from_utf8(content)?; let content = options.rustmft.reformat(&content)?;