Browse Source

add forbids from a CSV

main
Brian Hicks 2 years ago
parent
commit
f870420d55
  1. 41
      Cargo.lock
  2. 1
      Cargo.toml
  3. 37
      src/main.rs

41
Cargo.lock generated

@ -44,9 +44,18 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cc"
version = "1.0.62"
@ -185,6 +194,28 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "csv"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97"
dependencies = [
"bstr",
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "elm-forbid-import"
version = "0.1.0"
@ -193,6 +224,7 @@ dependencies = [
"cc",
"clap",
"crossbeam",
"csv",
"ignore",
"lazy_static",
"pathdiff",
@ -381,6 +413,15 @@ dependencies = [
"thread_local",
]
[[package]]
name = "regex-automata"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
dependencies = [
"byteorder",
]
[[package]]
name = "regex-syntax"
version = "0.6.21"

1
Cargo.toml

@ -11,6 +11,7 @@ license-file = "LICENSE"
anyhow = "1.0"
clap = "3.0.0-beta.2"
crossbeam = "0.8"
csv = "1.0"
ignore = "0.4"
lazy_static = "1.4"
pathdiff = "0.1"

37
src/main.rs

@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use clap::Clap;
use std::path::PathBuf;
use std::process;
@ -44,6 +44,13 @@ enum Mode {
hint: Option<String>,
},
/// Forbid a list of imports held in a CSV. The file should be a 2-column
/// CSV with "module" and "hint" fields and no headers.
ForbidFromCsv {
/// What file has the forbidden import list?
path: PathBuf,
},
/// Stop forbidding the use of a specific import.
Unforbid {
/// The fully-qualified name to forbid (e.g. `Html.Events`)
@ -126,6 +133,34 @@ fn run(opts: Options) -> Result<i32> {
Ok(0)
}
Mode::ForbidFromCsv { path } => {
let mut reader = csv::ReaderBuilder::new()
.flexible(true)
.has_headers(false)
.from_path(path)
.context("could not read the CSV of forbidden imports")?;
for record in reader.records() {
let mut record = record.context("could not read record")?;
record.trim();
let module = record
.get(0)
.and_then(|name| if !name.is_empty() { Some(name) } else { None })
.map(|name| name.to_string())
.ok_or(anyhow!(
"I need a module name in the first column of the CSV at "
))?;
let hint = record.get(1).map(|name| name.to_string());
store.forbid(module, hint);
}
store.write().context("could not update the config file")?;
Ok(1)
}
Mode::Unforbid { name } => {
store.unforbid(name);
store.write().context("could not update the config file")?;

Loading…
Cancel
Save