@@ -218,6 +218,8 @@ pub struct RenderOptions {
218
218
pub extern_html_root_urls : BTreeMap < String , String > ,
219
219
/// If present, suffix added to CSS/JavaScript files when referencing them in generated pages.
220
220
pub resource_suffix : String ,
221
+ /// Links displayed on the crate root page.
222
+ pub crate_root_links : BTreeMap < String , String > ,
221
223
/// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by
222
224
/// default.
223
225
//
@@ -270,6 +272,36 @@ impl Options {
270
272
/// Parses the given command-line for options. If an error message or other early-return has
271
273
/// been printed, returns `Err` with the exit code.
272
274
pub fn from_matches ( matches : & getopts:: Matches ) -> Result < Options , i32 > {
275
+ fn parse_keyval_opt_internal (
276
+ matches : & getopts:: Matches ,
277
+ opt_name : & ' static str ,
278
+ empty_err : & ' static str ,
279
+ invalid_form_err : & ' static str ,
280
+ ) -> Result < BTreeMap < String , String > , & ' static str > {
281
+ let mut externs = BTreeMap :: new ( ) ;
282
+ for arg in & ( matches) . opt_strs ( opt_name) {
283
+ let mut parts = arg. splitn ( 2 , '=' ) ;
284
+ let name = parts. next ( ) . ok_or ( empty_err) ?;
285
+ let url = parts. next ( ) . ok_or ( invalid_form_err) ?;
286
+ externs. insert ( name. to_string ( ) , url. to_string ( ) ) ;
287
+ }
288
+
289
+ Ok ( externs)
290
+ }
291
+ /// Extracts key-value arguments (such as for `--extern-html-root-url`) from `matches` and returns
292
+ /// a map of crate names to the given URLs. If an argument was ill-formed, returns an error
293
+ /// describing the issue.
294
+ macro_rules! parse_keyval_opt {
295
+ ( $matches: expr, $opt_name: literal) => {
296
+ parse_keyval_opt_internal(
297
+ $matches,
298
+ $opt_name,
299
+ concat!( "--" , $opt_name, "must not be empty" ) ,
300
+ concat!( "--" , $opt_name, "must be of the form name=url" ) ,
301
+ )
302
+ } ;
303
+ }
304
+
273
305
// Check for unstable options.
274
306
nightly_options:: check_nightly_options ( & matches, & opts ( ) ) ;
275
307
@@ -366,7 +398,15 @@ impl Options {
366
398
. map ( |s| SearchPath :: from_cli_opt ( s, error_format) )
367
399
. collect ( ) ;
368
400
let externs = parse_externs ( & matches, & debugging_options, error_format) ;
369
- let extern_html_root_urls = match parse_extern_html_roots ( & matches) {
401
+ let extern_html_root_urls = match parse_keyval_opt ! ( & matches, "extern-html-root-url" ) {
402
+ Ok ( ex) => ex,
403
+ Err ( err) => {
404
+ diag. struct_err ( err) . emit ( ) ;
405
+ return Err ( 1 ) ;
406
+ }
407
+ } ;
408
+
409
+ let crate_root_links = match parse_keyval_opt ! ( & matches, "crate-root-link" ) {
370
410
Ok ( ex) => ex,
371
411
Err ( err) => {
372
412
diag. struct_err ( err) . emit ( ) ;
@@ -609,6 +649,7 @@ impl Options {
609
649
generate_search_filter,
610
650
document_private,
611
651
document_hidden,
652
+ crate_root_links,
612
653
} ,
613
654
output_format,
614
655
} )
@@ -654,20 +695,3 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
654
695
}
655
696
}
656
697
}
657
-
658
- /// Extracts `--extern-html-root-url` arguments from `matches` and returns a map of crate names to
659
- /// the given URLs. If an `--extern-html-root-url` argument was ill-formed, returns an error
660
- /// describing the issue.
661
- fn parse_extern_html_roots (
662
- matches : & getopts:: Matches ,
663
- ) -> Result < BTreeMap < String , String > , & ' static str > {
664
- let mut externs = BTreeMap :: new ( ) ;
665
- for arg in & matches. opt_strs ( "extern-html-root-url" ) {
666
- let mut parts = arg. splitn ( 2 , '=' ) ;
667
- let name = parts. next ( ) . ok_or ( "--extern-html-root-url must not be empty" ) ?;
668
- let url = parts. next ( ) . ok_or ( "--extern-html-root-url must be of the form name=url" ) ?;
669
- externs. insert ( name. to_string ( ) , url. to_string ( ) ) ;
670
- }
671
-
672
- Ok ( externs)
673
- }
0 commit comments