@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
3
3
4
4
use clap:: { App , AppSettings , Arg , SubCommand } ;
5
5
use cratesfyi:: db:: { add_path_into_database, connect_db} ;
6
- use cratesfyi:: utils:: add_crate_to_queue;
6
+ use cratesfyi:: utils:: { add_crate_to_queue, remove_crate_priority , set_crate_priority } ;
7
7
use cratesfyi:: Server ;
8
8
use cratesfyi:: { db, DocBuilder , DocBuilderOptions , RustwideBuilder } ;
9
9
@@ -140,7 +140,26 @@ pub fn main() {
140
140
. short ( "p" )
141
141
. long ( "priority" )
142
142
. help ( "Priority of build (default: 5) (new crate builds get priority 0)" )
143
- . takes_value ( true ) ) ) )
143
+ . takes_value ( true ) ) )
144
+ . subcommand ( SubCommand :: with_name ( "priority" )
145
+ . about ( "Interactions with build queue priorities" )
146
+ . setting ( AppSettings :: ArgRequiredElseHelp )
147
+ . subcommand ( SubCommand :: with_name ( "set" )
148
+ . about ( "Set all crates matching the given pattern to a priority level" )
149
+ . arg ( Arg :: with_name ( "PATTERN" )
150
+ . index ( 1 )
151
+ . required ( true )
152
+ . help ( "See https://www.postgresql.org/docs/current/functions-matching.html" ) )
153
+ . arg ( Arg :: with_name ( "PRIORITY" )
154
+ . index ( 2 )
155
+ . required ( true )
156
+ . help ( "The priority to give crates matching PATTERN" ) )
157
+ . subcommand ( SubCommand :: with_name ( "remove" )
158
+ . about ( "Remove the prioritization of crates by the given pattern" )
159
+ . arg ( Arg :: with_name ( "PATTERN" )
160
+ . index ( 1 )
161
+ . required ( true )
162
+ . help ( "See https://www.postgresql.org/docs/current/functions-matching.html" ) ) ) ) ) )
144
163
. get_matches ( ) ;
145
164
146
165
if let Some ( matches) = matches. subcommand_matches ( "build" ) {
@@ -299,6 +318,29 @@ pub fn main() {
299
318
priority,
300
319
)
301
320
. expect ( "Could not add crate to queue" ) ;
321
+ } else if let Some ( matches) = matches. subcommand_matches ( "set" ) {
322
+ let pattern = matches
323
+ . value_of ( "PATTERN" )
324
+ . expect ( "You must give a pattern to match with" ) ;
325
+ let priority = clap:: value_t!( matches. value_of( "PRIORITY" ) , i32 )
326
+ . expect ( "You must give a priority for a crate" ) ;
327
+ let conn = connect_db ( ) . expect ( "Could not connect to the database" ) ;
328
+
329
+ set_crate_priority ( & conn, pattern, priority) . expect ( "Could not set pattern's priority" ) ;
330
+ } else if let Some ( matches) = matches. subcommand_matches ( "remove" ) {
331
+ let pattern = matches
332
+ . value_of ( "PATTERN" )
333
+ . expect ( "You must give a pattern to remove" ) ;
334
+ let conn = connect_db ( ) . expect ( "Could not connect to the database" ) ;
335
+
336
+ if remove_crate_priority ( & conn, pattern)
337
+ . expect ( "Could not remove pattern's priority" )
338
+ . is_some ( )
339
+ {
340
+ println ! ( "Removed pattern" ) ;
341
+ } else {
342
+ println ! ( "Pattern did not exist and so was not removed" ) ;
343
+ }
302
344
}
303
345
}
304
346
}
0 commit comments