@@ -12,9 +12,9 @@ use std::path::PathBuf;
12
12
13
13
use clap:: { Arg , App , SubCommand } ;
14
14
use cratesfyi:: { DocBuilder , DocBuilderOptions , db} ;
15
- use cratesfyi:: utils:: build_doc;
15
+ use cratesfyi:: utils:: { build_doc, add_crate_to_queue } ;
16
16
use cratesfyi:: start_web_server;
17
- use cratesfyi:: db:: add_path_into_database;
17
+ use cratesfyi:: db:: { add_path_into_database, connect_db } ;
18
18
19
19
20
20
pub fn main ( ) {
@@ -130,6 +130,23 @@ pub fn main() {
130
130
chart")
131
131
. subcommand ( SubCommand :: with_name ( "update-search-index" ) )
132
132
. about ( "Updates search index" ) )
133
+ . subcommand ( SubCommand :: with_name ( "queue" )
134
+ . about ( "Interactions with the build queue" )
135
+ . subcommand ( SubCommand :: with_name ( "add" )
136
+ . about ( "Add a crate to the build queue" )
137
+ . arg ( Arg :: with_name ( "CRATE_NAME" )
138
+ . index ( 1 )
139
+ . required ( true )
140
+ . help ( "Name of crate to build" ) )
141
+ . arg ( Arg :: with_name ( "CRATE_VERSION" )
142
+ . index ( 2 )
143
+ . required ( true )
144
+ . help ( "Version of crate to build" ) )
145
+ . arg ( Arg :: with_name ( "BUILD_PRIORITY" )
146
+ . short ( "p" )
147
+ . long ( "priority" )
148
+ . help ( "Priority of build (default: 5) (new crate builds get priority 0)" )
149
+ . takes_value ( true ) ) ) )
133
150
. get_matches ( ) ;
134
151
135
152
@@ -227,6 +244,17 @@ pub fn main() {
227
244
start_web_server ( Some ( matches. value_of ( "SOCKET_ADDR" ) . unwrap_or ( "0.0.0.0:3000" ) ) ) ;
228
245
} else if let Some ( _) = matches. subcommand_matches ( "daemon" ) {
229
246
cratesfyi:: utils:: start_daemon ( ) ;
247
+ } else if let Some ( matches) = matches. subcommand_matches ( "queue" ) {
248
+ if let Some ( matches) = matches. subcommand_matches ( "add" ) {
249
+ let priority = matches. value_of ( "BUILD_PRIORITY" ) . unwrap_or ( "5" ) ;
250
+ let priority: i32 = priority. parse ( ) . expect ( "--priority was not a number" ) ;
251
+ let conn = connect_db ( ) . expect ( "Could not connect to database" ) ;
252
+
253
+ add_crate_to_queue ( & conn,
254
+ matches. value_of ( "CRATE_NAME" ) . unwrap ( ) ,
255
+ matches. value_of ( "CRATE_VERSION" ) . unwrap ( ) ,
256
+ priority) . expect ( "Could not add crate to queue" ) ;
257
+ }
230
258
} else {
231
259
println ! ( "{}" , matches. usage( ) ) ;
232
260
}
0 commit comments