@@ -6,7 +6,8 @@ use std::sync::Arc;
66use docs_rs:: db:: { self , add_path_into_database, Pool , PoolClient } ;
77use docs_rs:: utils:: { remove_crate_priority, set_crate_priority} ;
88use docs_rs:: {
9- BuildQueue , Config , Context , DocBuilder , Index , Metrics , RustwideBuilder , Server , Storage ,
9+ BuildQueue , Config , Context , DocBuilder , Index , Metrics , PackageKind , RustwideBuilder , Server ,
10+ Storage ,
1011} ;
1112use failure:: { err_msg, Error , ResultExt } ;
1213use once_cell:: sync:: OnceCell ;
@@ -257,8 +258,16 @@ enum BuildSubcommand {
257258 #[ structopt( name = "CRATE_VERSION" ) ]
258259 crate_version : Option < String > ,
259260
261+ /// Url for registry different from cratesio
262+ #[ structopt( name = "CRATE_REGISTRY" ) ]
263+ crate_registry : Option < String > ,
264+
260265 /// Build a crate at a specific path
261- #[ structopt( short = "l" , long = "local" , conflicts_with_all( & [ "CRATE_NAME" , "CRATE_VERSION" ] ) ) ]
266+ #[ structopt(
267+ short = "l" ,
268+ long = "local" ,
269+ conflicts_with_all( & [ "CRATE_NAME" , "CRATE_VERSION" , "CRATE_REGISTRY" ] )
270+ ) ]
262271 local : Option < PathBuf > ,
263272 } ,
264273
@@ -299,6 +308,7 @@ impl BuildSubcommand {
299308 Self :: Crate {
300309 crate_name,
301310 crate_version,
311+ crate_registry,
302312 local,
303313 } => {
304314 let mut builder = rustwide_builder ( ) ?;
@@ -313,7 +323,10 @@ impl BuildSubcommand {
313323 & crate_name. ok_or_else ( || err_msg ( "must specify name if not local" ) ) ?,
314324 & crate_version
315325 . ok_or_else ( || err_msg ( "must specify version if not local" ) ) ?,
316- None ,
326+ crate_registry
327+ . as_ref ( )
328+ . map ( |s| PackageKind :: Registry ( s. as_str ( ) ) )
329+ . unwrap_or ( PackageKind :: CratesIo ) ,
317330 )
318331 . context ( "Building documentation failed" ) ?;
319332 }
@@ -593,7 +606,16 @@ impl Context for BinContext {
593606 fn index ( & self ) -> Result < Arc < Index > , Error > {
594607 Ok ( self
595608 . index
596- . get_or_try_init :: < _ , Error > ( || Ok ( Arc :: new ( Index :: new ( & * self . config ( ) ?) ?) ) ) ?
609+ . get_or_try_init :: < _ , Error > ( || {
610+ let config = self . config ( ) ?;
611+ Ok ( Arc :: new (
612+ if let Some ( registry_url) = config. registry_url . clone ( ) {
613+ Index :: from_url ( config. registry_index_path . clone ( ) , registry_url)
614+ } else {
615+ Index :: new ( config. registry_index_path . clone ( ) )
616+ } ?,
617+ ) )
618+ } ) ?
597619 . clone ( ) )
598620 }
599621}
0 commit comments