@@ -10,7 +10,8 @@ use docs_rs::cdn::CdnBackend;
10
10
use docs_rs:: db:: { self , add_path_into_database, Overrides , Pool , PoolClient } ;
11
11
use docs_rs:: repositories:: RepositoryStatsUpdater ;
12
12
use docs_rs:: utils:: {
13
- get_config, queue_builder, remove_crate_priority, set_crate_priority, ConfigName ,
13
+ get_config, get_crate_pattern_and_priority, list_crate_priorities, queue_builder,
14
+ remove_crate_priority, set_crate_priority, ConfigName ,
14
15
} ;
15
16
use docs_rs:: {
16
17
start_web_server, BuildQueue , Config , Context , Index , Metrics , PackageKind , RustwideBuilder ,
@@ -234,6 +235,14 @@ impl QueueSubcommand {
234
235
235
236
#[ derive( Debug , Clone , PartialEq , Eq , Subcommand ) ]
236
237
enum PrioritySubcommand {
238
+ /// Get priority for a crate
239
+ ///
240
+ /// (returns only the first matching pattern, there may be other matching patterns)
241
+ Get { crate_name : String } ,
242
+
243
+ /// List priorities for all patterns
244
+ List ,
245
+
237
246
/// Set all crates matching a pattern to a priority level
238
247
Set {
239
248
/// See https://www.postgresql.org/docs/current/functions-matching.html for pattern syntax
@@ -253,19 +262,37 @@ enum PrioritySubcommand {
253
262
254
263
impl PrioritySubcommand {
255
264
fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
265
+ let conn = & mut * ctx. conn ( ) ?;
256
266
match self {
267
+ Self :: List => {
268
+ for ( pattern, priority) in list_crate_priorities ( conn) ? {
269
+ println ! ( "{pattern:>20} : {priority:>3}" ) ;
270
+ }
271
+ }
272
+
273
+ Self :: Get { crate_name } => {
274
+ if let Some ( ( pattern, priority) ) =
275
+ get_crate_pattern_and_priority ( conn, & crate_name) ?
276
+ {
277
+ println ! ( "{pattern} : {priority}" ) ;
278
+ } else {
279
+ println ! ( "No priority found for {crate_name}" ) ;
280
+ }
281
+ }
282
+
257
283
Self :: Set { pattern, priority } => {
258
- set_crate_priority ( & mut * ctx . conn ( ) ? , & pattern, priority)
284
+ set_crate_priority ( conn, & pattern, priority)
259
285
. context ( "Could not set pattern's priority" ) ?;
286
+ println ! ( "Set pattern '{pattern}' to priority {priority}" ) ;
260
287
}
261
288
262
289
Self :: Remove { pattern } => {
263
- if let Some ( priority) = remove_crate_priority ( & mut * ctx . conn ( ) ? , & pattern)
290
+ if let Some ( priority) = remove_crate_priority ( conn, & pattern)
264
291
. context ( "Could not remove pattern's priority" ) ?
265
292
{
266
- println ! ( "Removed pattern with priority {priority}" ) ;
293
+ println ! ( "Removed pattern '{pattern}' with priority {priority}" ) ;
267
294
} else {
268
- println ! ( "Pattern did not exist and so was not removed" ) ;
295
+ println ! ( "Pattern '{pattern}' did not exist and so was not removed" ) ;
269
296
}
270
297
}
271
298
}
0 commit comments