Skip to content

Commit e5ba8ce

Browse files
authored
Merge pull request diesel-rs#1687 from dreid/prefer-include-exclude
Use include/exclude instead of whitelist/blacklist.
2 parents 58b6982 + a27b060 commit e5ba8ce

19 files changed

Lines changed: 67 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
5454
concerned about relying on deprecated code, we recommend attempting to build
5555
your app with `default-features` turned off (specifically excluding the
5656
`with-deprecated` feature).
57+
* The `--whitelist` and `--blacklist` options to `diesel print-schema` have been
58+
deprecated and renamed `--only-tables` and `--exclude-tables`.
5759

5860
## [1.2.2] - 2018-04-12
5961

diesel_cli/src/cli.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,39 @@ pub fn build_cli() -> App<'static, 'static> {
108108
.index(1)
109109
.takes_value(true)
110110
.multiple(true)
111-
.help("Table names to filter (default whitelist if not empty)"),
111+
.help("Table names to filter (default only-tables if not empty)"),
112+
)
113+
.arg(
114+
Arg::with_name("only-tables")
115+
.short("o")
116+
.long("only-tables")
117+
.help("Only include tables from table-name")
118+
.conflicts_with("except-tables")
119+
.conflicts_with("blacklist"),
112120
)
113121
.arg(
114122
Arg::with_name("whitelist")
115123
.short("w")
116124
.long("whitelist")
117-
.help("Use table list as whitelist")
118-
.conflicts_with("blacklist"),
125+
.hidden(true)
126+
.conflicts_with("blacklist")
127+
.conflicts_with("except-tables"),
128+
)
129+
.arg(
130+
Arg::with_name("except-tables")
131+
.short("e")
132+
.long("except-tables")
133+
.help("Exclude tables from table-name")
134+
.conflicts_with("only-tables")
135+
.conflicts_with("whitelist"),
119136
)
120137
.arg(
121138
Arg::with_name("blacklist")
122139
.short("b")
123140
.long("blacklist")
124-
.help("Use table list as blacklist")
125-
.conflicts_with("whitelist"),
141+
.hidden(true)
142+
.conflicts_with("whitelist")
143+
.conflicts_with("only-tables"),
126144
)
127145
.arg(
128146
Arg::with_name("with-docs")

diesel_cli/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,17 @@ fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<Error>> {
353353
.collect();
354354

355355
if matches.is_present("whitelist") {
356-
config.filter = Filtering::Whitelist(filter)
357-
} else if matches.is_present("blacklist") {
358-
config.filter = Filtering::Blacklist(filter)
356+
eprintln!("The `whitelist` option has been deprecated and renamed to `only-tables`.");
357+
}
358+
359+
if matches.is_present("blacklist") {
360+
eprintln!("The `whitelist` option has been deprecated and renamed to `except-tables`.");
361+
}
362+
363+
if matches.is_present("only-tables") || matches.is_present("whitelist") {
364+
config.filter = Filtering::OnlyTables(filter)
365+
} else if matches.is_present("except-tables") || matches.is_present("blacklist") {
366+
config.filter = Filtering::ExceptTables(filter)
359367
}
360368

361369
if matches.is_present("with-docs") {

diesel_cli/src/print_schema.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::process::Command;
1212
use tempfile::NamedTempFile;
1313

1414
pub enum Filtering {
15-
Whitelist(Vec<TableName>),
16-
Blacklist(Vec<TableName>),
15+
OnlyTables(Vec<TableName>),
16+
ExceptTables(Vec<TableName>),
1717
None,
1818
}
1919

@@ -28,8 +28,8 @@ impl Filtering {
2828
use self::Filtering::*;
2929

3030
match *self {
31-
Whitelist(ref names) => !names.contains(name),
32-
Blacklist(ref names) => names.contains(name),
31+
OnlyTables(ref names) => !names.contains(name),
32+
ExceptTables(ref names) => names.contains(name),
3333
None => false,
3434
}
3535
}
@@ -306,36 +306,41 @@ impl<'de> Deserialize<'de> for Filtering {
306306
type Value = Filtering;
307307

308308
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
309-
f.write_str("either a whitelist or a blacklist")
309+
f.write_str("either only-tables or except-tables")
310310
}
311311

312312
fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
313313
where
314314
V: MapAccess<'de>,
315315
{
316-
let mut whitelist = None;
317-
let mut blacklist = None;
316+
let mut only_tables = None;
317+
let mut except_tables = None;
318318
while let Some((key, value)) = map.next_entry()? {
319319
match key {
320-
"whitelist" => {
321-
if whitelist.is_some() {
322-
return Err(de::Error::duplicate_field("whitelist"));
320+
"only-tables" => {
321+
if only_tables.is_some() {
322+
return Err(de::Error::duplicate_field("only-tables"));
323323
}
324-
whitelist = Some(value);
324+
only_tables = Some(value);
325325
}
326-
"blacklist" => {
327-
if blacklist.is_some() {
328-
return Err(de::Error::duplicate_field("blacklist"));
326+
"except-tables" => {
327+
if except_tables.is_some() {
328+
return Err(de::Error::duplicate_field("except-tables"));
329329
}
330-
blacklist = Some(value);
330+
except_tables = Some(value);
331+
}
332+
_ => {
333+
return Err(de::Error::unknown_field(
334+
key,
335+
&["only-tables", "except-tables"],
336+
))
331337
}
332-
_ => return Err(de::Error::unknown_field(key, &["whitelist", "blacklist"])),
333338
}
334339
}
335-
match (whitelist, blacklist) {
336-
(Some(_), Some(_)) => Err(de::Error::duplicate_field("blacklist")),
337-
(Some(w), None) => Ok(Filtering::Whitelist(w)),
338-
(None, Some(b)) => Ok(Filtering::Blacklist(b)),
340+
match (only_tables, except_tables) {
341+
(Some(_), Some(_)) => Err(de::Error::duplicate_field("except-tables")),
342+
(Some(w), None) => Ok(Filtering::OnlyTables(w)),
343+
(None, Some(b)) => Ok(Filtering::ExceptTables(b)),
339344
(None, None) => Ok(Filtering::None),
340345
}
341346
}

diesel_cli/tests/print_schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ fn run_infer_schema() {
1515
}
1616

1717
#[test]
18-
fn run_infer_schema_whitelist() {
18+
fn run_infer_schema_include() {
1919
test_print_schema(
20-
"print_schema_whitelist",
20+
"print_schema_only_tables",
2121
vec!["--with-docs", "-w", "users1"],
2222
);
2323
}
2424

2525
#[test]
26-
fn run_infer_schema_blacklist() {
26+
fn run_infer_schema_exclude() {
2727
test_print_schema(
28-
"print_schema_blacklist",
28+
"print_schema_except_tables",
2929
vec!["--with-docs", "-b", "users1"],
3030
);
3131
}

diesel_cli/tests/print_schema/print_schema_whitelist/diesel.toml renamed to diesel_cli/tests/print_schema/print_schema_except_tables/diesel.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[print_schema]
22
file = "src/schema.rs"
33
with_docs = true
4-
filter = { whitelist = ["users1"] }
4+
filter = { except-tables = ["users1"] }

diesel_cli/tests/print_schema/print_schema_blacklist/mysql/expected.rs renamed to diesel_cli/tests/print_schema/print_schema_except_tables/mysql/expected.rs

File renamed without changes.

diesel_cli/tests/print_schema/print_schema_blacklist/mysql/schema.sql renamed to diesel_cli/tests/print_schema/print_schema_except_tables/mysql/schema.sql

File renamed without changes.

diesel_cli/tests/print_schema/print_schema_blacklist/postgres/expected.rs renamed to diesel_cli/tests/print_schema/print_schema_except_tables/postgres/expected.rs

File renamed without changes.

diesel_cli/tests/print_schema/print_schema_blacklist/postgres/schema.sql renamed to diesel_cli/tests/print_schema/print_schema_except_tables/postgres/schema.sql

File renamed without changes.

0 commit comments

Comments
 (0)