Skip to content

Commit 4664736

Browse files
Koenraad VerheydenJoshua Nelson
authored andcommitted
Make 'blacklist' a subcommand of 'database'
1 parent 7c38aa8 commit 4664736

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/bin/cratesfyi.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,6 @@ pub fn main() {
7777
.subcommand(SubCommand::with_name("unlock")
7878
.about("Unlocks cratesfyi daemon to continue building new crates"))
7979
.subcommand(SubCommand::with_name("print-options")))
80-
.subcommand(SubCommand::with_name("blacklist")
81-
.about("Blacklist operations")
82-
.setting(AppSettings::ArgRequiredElseHelp)
83-
.subcommand(SubCommand::with_name("add")
84-
.about("Add a crate to the blacklist")
85-
.arg(Arg::with_name("CRATE_NAME")
86-
.required(true)
87-
.help("Crate name")))
88-
.subcommand(SubCommand::with_name("remove")
89-
.about("Remove a crate from the blacklist")
90-
.arg(Arg::with_name("CRATE_NAME")
91-
.required(true)
92-
.help("Crate name"))))
9380
.subcommand(SubCommand::with_name("start-web-server")
9481
.about("Starts web server")
9582
.arg(Arg::with_name("SOCKET_ADDR")
@@ -129,7 +116,20 @@ pub fn main() {
129116
.arg(Arg::with_name("CRATE_NAME")
130117
.takes_value(true)
131118
.required(true)
132-
.help("Name of the crate to delete"))))
119+
.help("Name of the crate to delete")))
120+
.subcommand(SubCommand::with_name("blacklist")
121+
.about("Blacklist operations")
122+
.setting(AppSettings::ArgRequiredElseHelp)
123+
.subcommand(SubCommand::with_name("add")
124+
.about("Add a crate to the blacklist")
125+
.arg(Arg::with_name("CRATE_NAME")
126+
.required(true)
127+
.help("Crate name")))
128+
.subcommand(SubCommand::with_name("remove")
129+
.about("Remove a crate from the blacklist")
130+
.arg(Arg::with_name("CRATE_NAME")
131+
.required(true)
132+
.help("Crate name")))))
133133
.subcommand(SubCommand::with_name("queue")
134134
.about("Interactions with the build queue")
135135
.setting(AppSettings::ArgRequiredElseHelp)
@@ -213,18 +213,6 @@ pub fn main() {
213213
println!("{:?}", docbuilder.options());
214214
}
215215

216-
} else if let Some(matches) = matches.subcommand_matches("blacklist") {
217-
let conn = db::connect_db().expect("Failed to connect to the database");
218-
219-
if let Some(matches) = matches.subcommand_matches("add") {
220-
let crate_name = matches.value_of("CRATE_NAME").expect("Verified by clap");
221-
db::blacklist::add_crate(&conn, crate_name).expect("Failed to add crate to blacklist");
222-
223-
} else if let Some(matches) = matches.subcommand_matches("remove") {
224-
let crate_name = matches.value_of("CRATE_NAME").expect("Verified by clap");
225-
db::blacklist::remove_crate(&conn, crate_name).expect("Failed to remove crate from blacklist");
226-
}
227-
228216
} else if let Some(matches) = matches.subcommand_matches("database") {
229217
if let Some(matches) = matches.subcommand_matches("migrate") {
230218
let version = matches.value_of("VERSION").map(|v| v.parse::<i64>()
@@ -260,6 +248,17 @@ pub fn main() {
260248
let name = matches.value_of("CRATE_NAME").expect("missing crate name");
261249
let conn = db::connect_db().expect("failed to connect to the database");
262250
db::delete_crate(&conn, &name).expect("failed to delete the crate");
251+
} else if let Some(matches) = matches.subcommand_matches("blacklist") {
252+
let conn = db::connect_db().expect("failed to connect to the database");
253+
254+
if let Some(matches) = matches.subcommand_matches("add") {
255+
let crate_name = matches.value_of("CRATE_NAME").expect("verified by clap");
256+
db::blacklist::add_crate(&conn, crate_name).expect("failed to add crate to blacklist");
257+
258+
} else if let Some(matches) = matches.subcommand_matches("remove") {
259+
let crate_name = matches.value_of("CRATE_NAME").expect("verified by clap");
260+
db::blacklist::remove_crate(&conn, crate_name).expect("failed to remove crate from blacklist");
261+
}
263262
}
264263

265264
} else if let Some(matches) = matches.subcommand_matches("start-web-server") {

0 commit comments

Comments
 (0)