From 30ba2301d836dab00806fb9e2dc8b8dae7c962a9 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 13:49:17 -0500 Subject: [PATCH 01/13] Lookin queute --- src/docbuilder/queue.rs | 6 +- src/utils/mod.rs | 2 +- src/utils/queue.rs | 184 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 3 deletions(-) diff --git a/src/docbuilder/queue.rs b/src/docbuilder/queue.rs index 39027cb6a..cf0cc3e49 100644 --- a/src/docbuilder/queue.rs +++ b/src/docbuilder/queue.rs @@ -3,7 +3,7 @@ use super::{DocBuilder, RustwideBuilder}; use crate::db::connect_db; use crate::error::Result; -use crate::utils::add_crate_to_queue; +use crate::utils::{add_crate_to_queue, get_crate_priority}; use crates_index_diff::{ChangeKind, Index}; impl DocBuilder { @@ -19,7 +19,9 @@ impl DocBuilder { changes.reverse(); for krate in changes.iter().filter(|k| k.kind != ChangeKind::Yanked) { - add_crate_to_queue(&conn, &krate.name, &krate.version, 0).ok(); + let priority = get_crate_priority(&conn, &krate.name)?; + add_crate_to_queue(&conn, &krate.name, &krate.version, priority).ok(); + debug!("{}-{} added into build queue", krate.name, krate.version); add_count += 1; } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 68a76f715..480a57fd2 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,7 +5,7 @@ pub(crate) use self::copy::copy_doc_dir; pub use self::daemon::start_daemon; pub use self::github_updater::github_updater; pub use self::html::extract_head_and_body; -pub use self::queue::add_crate_to_queue; +pub use self::queue::{add_crate_to_queue, get_crate_priority}; pub use self::release_activity_updater::update_release_activity; pub(crate) use self::rustc_version::parse_rustc_version; diff --git a/src/utils/queue.rs b/src/utils/queue.rs index a1961c041..47a309022 100644 --- a/src/utils/queue.rs +++ b/src/utils/queue.rs @@ -3,6 +3,26 @@ use crate::error::Result; use postgres::Connection; +/// The default queue priority +const DEFAULT_PRIORITY: i32 = 0; + +/// Get the build queue priority for a crate +pub fn get_crate_priority(conn: &Connection, name: &str) -> Result { + // Search the `priority` table for a priority where the crate name matches the stored pattern + let query = conn.query( + "SELECT priority FROM crate_priorities WHERE $1 LIKE pattern LIMIT 1", + &[&name], + )?; + + // If no match is found, return the default priority + if let Some(row) = query.iter().next() { + Ok(row.get(0)) + } else { + Ok(DEFAULT_PRIORITY) + } +} + +/// Adds a crate to the build queue to be built by rustdoc. `priority` should be gotten from `get_crate_priority` pub fn add_crate_to_queue( conn: &Connection, name: &str, @@ -13,5 +33,169 @@ pub fn add_crate_to_queue( "INSERT INTO queue (name, version, priority) VALUES ($1, $2, $3)", &[&name, &version, &priority], )?; + Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test::wrapper; + + /// Set all crates that match [`pattern`] to have a certain priority + /// + /// Note: `pattern` is used in a `LIKE` statement, so it must follow the postgres like syntax + /// + /// [`pattern`]: https://www.postgresql.org/docs/8.3/functions-matching.html + pub fn set_crate_priority(conn: &Connection, pattern: &str, priority: i32) -> Result<()> { + conn.query( + "INSERT INTO crate_priorities (pattern, priority) VALUES ($1, $2)", + &[&pattern, &priority], + )?; + + Ok(()) + } + + /// Remove a pattern from the priority table, returning the priority that it was associated with or `None` + /// if nothing was removed + pub fn remove_crate_priority(conn: &Connection, pattern: &str) -> Result> { + let query = conn.query( + "DELETE FROM crate_priorities WHERE pattern = $1 RETURNING priority", + &[&pattern], + )?; + + Ok(query.iter().next().map(|row| row.get(0))) + } + + #[test] + fn set_priority() { + wrapper(|env| { + let db = env.db(); + + set_crate_priority(&db.conn(), "cratesfyi-%", -100)?; + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-database")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-s3")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-webserver")?, -100); + assert_eq!( + get_crate_priority(&db.conn(), "cratesfyi")?, + DEFAULT_PRIORITY + ); + + set_crate_priority(&db.conn(), "_c_", 100)?; + assert_eq!(get_crate_priority(&db.conn(), "rcc")?, 100); + assert_eq!(get_crate_priority(&db.conn(), "rc")?, DEFAULT_PRIORITY); + + set_crate_priority(&db.conn(), "hexponent", 10)?; + assert_eq!(get_crate_priority(&db.conn(), "hexponent")?, 10); + assert_eq!( + get_crate_priority(&db.conn(), "hexponents")?, + DEFAULT_PRIORITY + ); + assert_eq!( + get_crate_priority(&db.conn(), "floathexponent")?, + DEFAULT_PRIORITY + ); + + Ok(()) + }) + } + + #[test] + fn remove_priority() { + wrapper(|env| { + let db = env.db(); + + set_crate_priority(&db.conn(), "cratesfyi-%", -100)?; + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-")?, -100); + + assert_eq!( + remove_crate_priority(&db.conn(), "cratesfyi-%")?, + Some(-100) + ); + assert_eq!( + get_crate_priority(&db.conn(), "cratesfyi-")?, + DEFAULT_PRIORITY + ); + + Ok(()) + }) + } + + #[test] + fn get_priority() { + wrapper(|env| { + let db = env.db(); + + set_crate_priority(&db.conn(), "cratesfyi-%", -100)?; + + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-database")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-s3")?, -100); + assert_eq!(get_crate_priority(&db.conn(), "cratesfyi-webserver")?, -100); + assert_eq!( + get_crate_priority(&db.conn(), "unrelated")?, + DEFAULT_PRIORITY + ); + + Ok(()) + }) + } + + #[test] + fn get_default_priority() { + wrapper(|env| { + let db = env.db(); + + assert_eq!( + get_crate_priority(&db.conn(), "cratesfyi")?, + DEFAULT_PRIORITY + ); + assert_eq!(get_crate_priority(&db.conn(), "rcc")?, DEFAULT_PRIORITY); + assert_eq!(get_crate_priority(&db.conn(), "lasso")?, DEFAULT_PRIORITY); + assert_eq!( + get_crate_priority(&db.conn(), "hexponent")?, + DEFAULT_PRIORITY + ); + assert_eq!( + get_crate_priority(&db.conn(), "rust4lyfe")?, + DEFAULT_PRIORITY + ); + + Ok(()) + }) + } + + #[test] + fn add_to_queue() { + wrapper(|env| { + let db = env.db(); + + let test_crates = [ + ("rcc", "0.1.0", 2), + ("lasso", "0.1.0", -1), + ("hexponent", "0.1.0", 0), + ("destroy-all-humans", "0.0.0-alpha", -100000), + ("totally-not-destroying-humans", "0.0.1", 0), + ]; + + for (name, version, priority) in test_crates.iter() { + add_crate_to_queue(&db.conn(), name, version, *priority)?; + + let query = db.conn().query( + "SELECT name, version, priority FROM queue WHERE name = $1", + &[&name], + )?; + + assert!(query.len() == 1); + let row = query.iter().next().unwrap(); + + assert_eq!(&row.get::<_, String>(0), name); + assert_eq!(&row.get::<_, String>(1), version); + assert_eq!(row.get::<_, i32>(2), *priority); + } + + Ok(()) + }) + } +} From e265846327dad2658e55da176fa875206eb71e4e Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 14:33:31 -0500 Subject: [PATCH 02/13] Update src/db/migrate.rs Co-Authored-By: Joshua Nelson --- src/db/migrate.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/db/migrate.rs b/src/db/migrate.rs index 8edb63958..e84c7cdb6 100644 --- a/src/db/migrate.rs +++ b/src/db/migrate.rs @@ -295,6 +295,20 @@ pub fn migrate(version: Option, conn: &Connection) -> CratesfyiResult<( DROP FUNCTION normalize_crate_name; " ), + migration!( + context, + // version + 11, + // description + "Allow crates to be given a different default priority", + // upgrade query + "CREATE TABLE crate_priorities ( + pattern VARCHAR NOT NULL PRIMARY KEY, + priority INTEGER NOT NULL + );", + // downgrade query + "DROP TABLE crate_priorities;", + ), ]; for migration in migrations { From 142d7201aa5a2317a3d9fc67c487dd1b45770f92 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 14:33:55 -0500 Subject: [PATCH 03/13] Update src/db/migrate.rs Co-Authored-By: Joshua Nelson --- src/db/migrate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/migrate.rs b/src/db/migrate.rs index e84c7cdb6..e533f1abb 100644 --- a/src/db/migrate.rs +++ b/src/db/migrate.rs @@ -303,7 +303,7 @@ pub fn migrate(version: Option, conn: &Connection) -> CratesfyiResult<( "Allow crates to be given a different default priority", // upgrade query "CREATE TABLE crate_priorities ( - pattern VARCHAR NOT NULL PRIMARY KEY, + pattern VARCHAR NOT NULL UNIQUE, priority INTEGER NOT NULL );", // downgrade query From cf1c3f8a6add54a564065424bcdc833bc56cc396 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 14:34:20 -0500 Subject: [PATCH 04/13] Update src/utils/queue.rs Co-Authored-By: Joshua Nelson --- src/utils/queue.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/queue.rs b/src/utils/queue.rs index 47a309022..99d9f3519 100644 --- a/src/utils/queue.rs +++ b/src/utils/queue.rs @@ -3,7 +3,6 @@ use crate::error::Result; use postgres::Connection; -/// The default queue priority const DEFAULT_PRIORITY: i32 = 0; /// Get the build queue priority for a crate From 0f77290d91dbb37e45bed7bd24020ba3c4b436a5 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 15:26:37 -0500 Subject: [PATCH 05/13] Exposed priority commands to the binary --- src/bin/cratesfyi.rs | 46 ++++++++++++++++++++++++++++++++++++++-- src/utils/mod.rs | 4 +++- src/utils/queue.rs | 50 ++++++++++++++++++++++---------------------- 3 files changed, 72 insertions(+), 28 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index fc7c995b9..f15e2464c 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use clap::{App, AppSettings, Arg, SubCommand}; use cratesfyi::db::{add_path_into_database, connect_db}; -use cratesfyi::utils::add_crate_to_queue; +use cratesfyi::utils::{add_crate_to_queue, remove_crate_priority, set_crate_priority}; use cratesfyi::Server; use cratesfyi::{db, DocBuilder, DocBuilderOptions, RustwideBuilder}; @@ -139,7 +139,26 @@ pub fn main() { .short("p") .long("priority") .help("Priority of build (default: 5) (new crate builds get priority 0)") - .takes_value(true)))) + .takes_value(true))) + .subcommand(SubCommand::with_name("priority") + .about("Interactions with build queue priorities") + .setting(AppSettings::ArgRequiredElseHelp) + .subcommand(SubCommand::with_name("set") + .about("Set all crates matching the given pattern to a priority level") + .arg(Arg::with_name("PATTERN") + .index(1) + .required(true) + .help("See https://www.postgresql.org/docs/current/functions-matching.html")) + .arg(Arg::with_name("PRIORITY") + .index(2) + .required(true) + .help("The priority to give crates matching PATTERN")) + .subcommand(SubCommand::with_name("remove") + .about("Remove the prioritization of crates by the given pattern") + .arg(Arg::with_name("PATTERN") + .index(1) + .required(true) + .help("See https://www.postgresql.org/docs/current/functions-matching.html")))))) .get_matches(); if let Some(matches) = matches.subcommand_matches("build") { @@ -298,6 +317,29 @@ pub fn main() { priority, ) .expect("Could not add crate to queue"); + } else if let Some(matches) = matches.subcommand_matches("set") { + let pattern = matches + .value_of("PATTERN") + .expect("You must give a pattern to match with"); + let priority = clap::value_t!(matches.value_of("PRIORITY"), i32) + .expect("You must give a priority for a crate"); + let conn = connect_db().expect("Could not connect to the database"); + + set_crate_priority(&conn, pattern, priority).expect("Could not set pattern's priority"); + } else if let Some(matches) = matches.subcommand_matches("remove") { + let pattern = matches + .value_of("PATTERN") + .expect("You must give a pattern to remove"); + let conn = connect_db().expect("Could not connect to the database"); + + if remove_crate_priority(&conn, pattern) + .expect("Could not remove pattern's priority") + .is_some() + { + println!("Removed pattern"); + } else { + println!("Pattern did not exist and so was not removed"); + } } } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 480a57fd2..423eb9d54 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,7 +5,9 @@ pub(crate) use self::copy::copy_doc_dir; pub use self::daemon::start_daemon; pub use self::github_updater::github_updater; pub use self::html::extract_head_and_body; -pub use self::queue::{add_crate_to_queue, get_crate_priority}; +pub use self::queue::{ + add_crate_to_queue, get_crate_priority, remove_crate_priority, set_crate_priority, +}; pub use self::release_activity_updater::update_release_activity; pub(crate) use self::rustc_version::parse_rustc_version; diff --git a/src/utils/queue.rs b/src/utils/queue.rs index 99d9f3519..abe5472bf 100644 --- a/src/utils/queue.rs +++ b/src/utils/queue.rs @@ -21,6 +21,31 @@ pub fn get_crate_priority(conn: &Connection, name: &str) -> Result { } } +/// Set all crates that match [`pattern`] to have a certain priority +/// +/// Note: `pattern` is used in a `LIKE` statement, so it must follow the postgres like syntax +/// +/// [`pattern`]: https://www.postgresql.org/docs/8.3/functions-matching.html +pub fn set_crate_priority(conn: &Connection, pattern: &str, priority: i32) -> Result<()> { + conn.query( + "INSERT INTO crate_priorities (pattern, priority) VALUES ($1, $2)", + &[&pattern, &priority], + )?; + + Ok(()) +} + +/// Remove a pattern from the priority table, returning the priority that it was associated with or `None` +/// if nothing was removed +pub fn remove_crate_priority(conn: &Connection, pattern: &str) -> Result> { + let query = conn.query( + "DELETE FROM crate_priorities WHERE pattern = $1 RETURNING priority", + &[&pattern], + )?; + + Ok(query.iter().next().map(|row| row.get(0))) +} + /// Adds a crate to the build queue to be built by rustdoc. `priority` should be gotten from `get_crate_priority` pub fn add_crate_to_queue( conn: &Connection, @@ -41,31 +66,6 @@ mod tests { use super::*; use crate::test::wrapper; - /// Set all crates that match [`pattern`] to have a certain priority - /// - /// Note: `pattern` is used in a `LIKE` statement, so it must follow the postgres like syntax - /// - /// [`pattern`]: https://www.postgresql.org/docs/8.3/functions-matching.html - pub fn set_crate_priority(conn: &Connection, pattern: &str, priority: i32) -> Result<()> { - conn.query( - "INSERT INTO crate_priorities (pattern, priority) VALUES ($1, $2)", - &[&pattern, &priority], - )?; - - Ok(()) - } - - /// Remove a pattern from the priority table, returning the priority that it was associated with or `None` - /// if nothing was removed - pub fn remove_crate_priority(conn: &Connection, pattern: &str) -> Result> { - let query = conn.query( - "DELETE FROM crate_priorities WHERE pattern = $1 RETURNING priority", - &[&pattern], - )?; - - Ok(query.iter().next().map(|row| row.get(0))) - } - #[test] fn set_priority() { wrapper(|env| { From 02defe2102877ff4409b0c3031db1162ef4cf490 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 19:39:42 -0500 Subject: [PATCH 06/13] Update src/bin/cratesfyi.rs Co-Authored-By: Joshua Nelson --- src/bin/cratesfyi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index f15e2464c..bc503c750 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -152,7 +152,7 @@ pub fn main() { .arg(Arg::with_name("PRIORITY") .index(2) .required(true) - .help("The priority to give crates matching PATTERN")) + .help("The priority to give crates matching PATTERN"))) .subcommand(SubCommand::with_name("remove") .about("Remove the prioritization of crates by the given pattern") .arg(Arg::with_name("PATTERN") From e332de58854bf49acc129b5dd3d614e337b66bc5 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 19:39:58 -0500 Subject: [PATCH 07/13] Update src/bin/cratesfyi.rs Co-Authored-By: Joshua Nelson --- src/bin/cratesfyi.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index bc503c750..eea654f6a 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -332,11 +332,10 @@ pub fn main() { .expect("You must give a pattern to remove"); let conn = connect_db().expect("Could not connect to the database"); - if remove_crate_priority(&conn, pattern) + if let Some(priority) = remove_crate_priority(&conn, pattern) .expect("Could not remove pattern's priority") - .is_some() { - println!("Removed pattern"); + println!("Removed pattern with priority {}", priority); } else { println!("Pattern did not exist and so was not removed"); } From f6cd31ea91156d54daaf214c01eae07be2e1ce20 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 20:24:53 -0500 Subject: [PATCH 08/13] I've been lied to, things will never be the same. You've tricked me the last time, Jyn. Fool me once, shame on you. Fool me twice... well, it looks like I really am the fool, now aren't I? You, sitting there with your code reviews, adding suggestions "Remove this! Add that! This is critically broken and threatens the stability of our infrastructure!". Well I've had enough. I'm through with your deceit and trickery, for this is the last straw. This is the straw that broke the camel's back, and this camel isn't particularly happy about its back being broken. No, this camel is done with it all! Off with the straw! No longer will I sit here, straw being piled on my back by a malicious taskmaster, breaking my back over pull requests, only to be broken again and again. This is the end, I am free now! --- src/bin/cratesfyi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index eea654f6a..9b9daca9f 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -158,7 +158,7 @@ pub fn main() { .arg(Arg::with_name("PATTERN") .index(1) .required(true) - .help("See https://www.postgresql.org/docs/current/functions-matching.html")))))) + .help("See https://www.postgresql.org/docs/current/functions-matching.html"))))) .get_matches(); if let Some(matches) = matches.subcommand_matches("build") { From fa0e9d6bbcc3f4c333ab8f968341df82c59d15c6 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 21:04:27 -0500 Subject: [PATCH 09/13] You really want to do that rustfmt? --- src/bin/cratesfyi.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 9b9daca9f..94c367061 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -332,8 +332,8 @@ pub fn main() { .expect("You must give a pattern to remove"); let conn = connect_db().expect("Could not connect to the database"); - if let Some(priority) = remove_crate_priority(&conn, pattern) - .expect("Could not remove pattern's priority") + if let Some(priority) = + remove_crate_priority(&conn, pattern).expect("Could not remove pattern's priority") { println!("Removed pattern with priority {}", priority); } else { From 4e0ea55f1f630bfd4c08dac0602cf7540dc03319 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Tue, 14 Apr 2020 13:12:24 -0500 Subject: [PATCH 10/13] Renamed subcommand --- src/bin/cratesfyi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 94c367061..b220fa307 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -140,7 +140,7 @@ pub fn main() { .long("priority") .help("Priority of build (default: 5) (new crate builds get priority 0)") .takes_value(true))) - .subcommand(SubCommand::with_name("priority") + .subcommand(SubCommand::with_name("default-priority") .about("Interactions with build queue priorities") .setting(AppSettings::ArgRequiredElseHelp) .subcommand(SubCommand::with_name("set") From 86c84f8c2687f88f8a9b74f3d69df71edac7f322 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Mon, 13 Apr 2020 13:49:17 -0500 Subject: [PATCH 11/13] Lookin queute --- src/utils/queue.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/queue.rs b/src/utils/queue.rs index abe5472bf..e0ce3f5d6 100644 --- a/src/utils/queue.rs +++ b/src/utils/queue.rs @@ -45,7 +45,6 @@ pub fn remove_crate_priority(conn: &Connection, pattern: &str) -> Result Date: Mon, 13 Apr 2020 15:26:37 -0500 Subject: [PATCH 12/13] Exposed priority commands to the binary --- src/utils/queue.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/queue.rs b/src/utils/queue.rs index e0ce3f5d6..abe5472bf 100644 --- a/src/utils/queue.rs +++ b/src/utils/queue.rs @@ -45,6 +45,7 @@ pub fn remove_crate_priority(conn: &Connection, pattern: &str) -> Result Date: Wed, 15 Apr 2020 08:39:03 -0500 Subject: [PATCH 13/13] Fixed cli args --- src/bin/cratesfyi.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index b220fa307..f0720c179 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -317,27 +317,30 @@ pub fn main() { priority, ) .expect("Could not add crate to queue"); - } else if let Some(matches) = matches.subcommand_matches("set") { - let pattern = matches - .value_of("PATTERN") - .expect("You must give a pattern to match with"); - let priority = clap::value_t!(matches.value_of("PRIORITY"), i32) - .expect("You must give a priority for a crate"); - let conn = connect_db().expect("Could not connect to the database"); + } else if let Some(matches) = matches.subcommand_matches("default-priority") { + if let Some(matches) = matches.subcommand_matches("set") { + let pattern = matches + .value_of("PATTERN") + .expect("You must give a pattern to match with"); + let priority = clap::value_t!(matches.value_of("PRIORITY"), i32) + .expect("You must give a priority for a crate"); + let conn = connect_db().expect("Could not connect to the database"); - set_crate_priority(&conn, pattern, priority).expect("Could not set pattern's priority"); - } else if let Some(matches) = matches.subcommand_matches("remove") { - let pattern = matches - .value_of("PATTERN") - .expect("You must give a pattern to remove"); - let conn = connect_db().expect("Could not connect to the database"); + set_crate_priority(&conn, pattern, priority) + .expect("Could not set pattern's priority"); + } else if let Some(matches) = matches.subcommand_matches("remove") { + let pattern = matches + .value_of("PATTERN") + .expect("You must give a pattern to remove"); + let conn = connect_db().expect("Could not connect to the database"); - if let Some(priority) = - remove_crate_priority(&conn, pattern).expect("Could not remove pattern's priority") - { - println!("Removed pattern with priority {}", priority); - } else { - println!("Pattern did not exist and so was not removed"); + if let Some(priority) = remove_crate_priority(&conn, pattern) + .expect("Could not remove pattern's priority") + { + println!("Removed pattern with priority {}", priority); + } else { + println!("Pattern did not exist and so was not removed"); + } } } }