Skip to content

Commit

Permalink
refactor(codegen): Hard code data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Oct 28, 2019
1 parent 1cbdb3a commit 5de368a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions dict/typos/codegen/src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {}",
Expand All @@ -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();
Expand All @@ -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)]
Expand All @@ -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
};
let mut content = vec![];
generate(&mut content);

let content = String::from_utf8(content)?;
let content = options.rustmft.reformat(&content)?;
Expand Down

0 comments on commit 5de368a

Please sign in to comment.