Skip to content

Commit 949bc86

Browse files
KixironJoshua Nelson
authored andcommitted
Added queue subcommands
1 parent d4aa301 commit 949bc86

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

src/bin/cratesfyi.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use std::env;
22
use std::path::PathBuf;
33

44
use cratesfyi::db::{self, add_path_into_database, connect_db};
5-
use cratesfyi::utils::add_crate_to_queue;
5+
use cratesfyi::utils::{add_crate_to_queue, remove_crate_priority, set_crate_priority};
66
use cratesfyi::Server;
77
use cratesfyi::{DocBuilder, DocBuilderOptions, RustwideBuilder};
88
use structopt::StructOpt;
99

1010
pub fn main() {
11-
let _ = dotenv::dotenv();
1211
logger_init();
1312

1413
CommandLine::from_args().handle_args();
@@ -107,6 +106,12 @@ enum QueueSubcommand {
107106
)]
108107
build_priority: i32,
109108
},
109+
110+
/// Interactions with build queue priorities
111+
DefaultPriority {
112+
#[structopt(subcommand)]
113+
subcommand: PrioritySubcommand,
114+
},
110115
}
111116

112117
impl QueueSubcommand {
@@ -121,6 +126,52 @@ impl QueueSubcommand {
121126
add_crate_to_queue(&conn, &crate_name, &crate_version, build_priority)
122127
.expect("Could not add crate to queue");
123128
}
129+
130+
Self::DefaultPriority { subcommand } => subcommand.handle_args(),
131+
}
132+
}
133+
}
134+
135+
#[derive(Debug, Clone, PartialEq, Eq, StructOpt)]
136+
enum PrioritySubcommand {
137+
/// Set all crates matching a pattern to a priority level
138+
Set {
139+
/// See https://www.postgresql.org/docs/current/functions-matching.html for pattern syntax
140+
#[structopt(name = "PATTERN")]
141+
pattern: String,
142+
/// The priority to give crates matching the given `PATTERN`
143+
priority: i32,
144+
},
145+
146+
/// Remove the prioritization of crates for a pattern
147+
Remove {
148+
/// See https://www.postgresql.org/docs/current/functions-matching.html for pattern syntax
149+
#[structopt(name = "PATTERN")]
150+
pattern: String,
151+
},
152+
}
153+
154+
impl PrioritySubcommand {
155+
pub fn handle_args(self) {
156+
match self {
157+
Self::Set { pattern, priority } => {
158+
let conn = connect_db().expect("Could not connect to the database");
159+
160+
set_crate_priority(&conn, &pattern, priority)
161+
.expect("Could not set pattern's priority");
162+
}
163+
164+
Self::Remove { pattern } => {
165+
let conn = connect_db().expect("Could not connect to the database");
166+
167+
if let Some(priority) = remove_crate_priority(&conn, &pattern)
168+
.expect("Could not remove pattern's priority")
169+
{
170+
println!("Removed pattern with priority {}", priority);
171+
} else {
172+
println!("Pattern did not exist and so was not removed");
173+
}
174+
}
124175
}
125176
}
126177
}

0 commit comments

Comments
 (0)