@@ -10,7 +10,8 @@ use docs_rs::cdn::CdnBackend;
1010use docs_rs:: db:: { self , add_path_into_database, Overrides , Pool , PoolClient } ;
1111use docs_rs:: repositories:: RepositoryStatsUpdater ;
1212use 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 ,
1415} ;
1516use docs_rs:: {
1617 start_web_server, BuildQueue , Config , Context , Index , Metrics , PackageKind , RustwideBuilder ,
@@ -234,6 +235,14 @@ impl QueueSubcommand {
234235
235236#[ derive( Debug , Clone , PartialEq , Eq , Subcommand ) ]
236237enum 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+
237246 /// Set all crates matching a pattern to a priority level
238247 Set {
239248 /// See https://www.postgresql.org/docs/current/functions-matching.html for pattern syntax
@@ -253,19 +262,37 @@ enum PrioritySubcommand {
253262
254263impl PrioritySubcommand {
255264 fn handle_args ( self , ctx : BinContext ) -> Result < ( ) > {
265+ let conn = & mut * ctx. conn ( ) ?;
256266 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+
257283 Self :: Set { pattern, priority } => {
258- set_crate_priority ( & mut * ctx . conn ( ) ? , & pattern, priority)
284+ set_crate_priority ( conn, & pattern, priority)
259285 . context ( "Could not set pattern's priority" ) ?;
286+ println ! ( "Set pattern '{pattern}' to priority {priority}" ) ;
260287 }
261288
262289 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)
264291 . context ( "Could not remove pattern's priority" ) ?
265292 {
266- println ! ( "Removed pattern with priority {priority}" ) ;
293+ println ! ( "Removed pattern '{pattern}' with priority {priority}" ) ;
267294 } else {
268- println ! ( "Pattern did not exist and so was not removed" ) ;
295+ println ! ( "Pattern '{pattern}' did not exist and so was not removed" ) ;
269296 }
270297 }
271298 }
0 commit comments