@@ -2,13 +2,12 @@ use std::env;
2
2
use std:: path:: PathBuf ;
3
3
4
4
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 } ;
6
6
use cratesfyi:: Server ;
7
7
use cratesfyi:: { DocBuilder , DocBuilderOptions , RustwideBuilder } ;
8
8
use structopt:: StructOpt ;
9
9
10
10
pub fn main ( ) {
11
- let _ = dotenv:: dotenv ( ) ;
12
11
logger_init ( ) ;
13
12
14
13
CommandLine :: from_args ( ) . handle_args ( ) ;
@@ -107,6 +106,12 @@ enum QueueSubcommand {
107
106
) ]
108
107
build_priority : i32 ,
109
108
} ,
109
+
110
+ /// Interactions with build queue priorities
111
+ DefaultPriority {
112
+ #[ structopt( subcommand) ]
113
+ subcommand : PrioritySubcommand ,
114
+ } ,
110
115
}
111
116
112
117
impl QueueSubcommand {
@@ -121,6 +126,52 @@ impl QueueSubcommand {
121
126
add_crate_to_queue ( & conn, & crate_name, & crate_version, build_priority)
122
127
. expect ( "Could not add crate to queue" ) ;
123
128
}
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
+ }
124
175
}
125
176
}
126
177
}
0 commit comments