@@ -379,28 +379,23 @@ pub fn cli() -> App<'static, 'static> {
379
379
. long ( "path" )
380
380
. help ( "Only print the path to the documentation" ) ,
381
381
)
382
- . arg (
383
- Arg :: with_name ( "book" )
384
- . long ( "book" )
385
- . help ( "The Rust Programming Language book" ) ,
386
- )
387
- . arg (
388
- Arg :: with_name ( "std" )
389
- . long ( "std" )
390
- . help ( "Standard library API documentation" ) ,
391
- )
392
- . arg (
393
- Arg :: with_name ( "reference" )
394
- . long ( "reference" )
395
- . help ( "The Rust Reference" ) ,
382
+ . args (
383
+ & DOCS_DATA . into_iter ( ) . map ( |( name, help_msg, _) | {
384
+ Arg :: with_name ( name)
385
+ . long ( name)
386
+ . help ( help_msg)
387
+ } ) . collect :: < Vec < _ > > ( )
396
388
)
397
389
. arg (
398
390
Arg :: with_name ( "toolchain" )
399
391
. help ( TOOLCHAIN_ARG_HELP )
400
392
. long ( "toolchain" )
401
393
. takes_value ( true ) ,
402
394
)
403
- . group ( ArgGroup :: with_name ( "page" ) . args ( & [ "book" , "std" , "reference" ] ) ) ,
395
+ . group ( ArgGroup :: with_name ( "page" ) . args (
396
+ & DOCS_DATA . into_iter ( ) . map ( |( name, _, _) | * name)
397
+ . collect :: < Vec < _ > > ( )
398
+ ) ) ,
404
399
) ;
405
400
406
401
if cfg ! ( not( target_os = "windows" ) ) {
@@ -950,17 +945,34 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
950
945
Ok ( ( ) )
951
946
}
952
947
948
+ const DOCS_DATA : & [ ( & ' static str , & ' static str , & ' static str , ) ] = & [
949
+ // flags can be used to open specific documents, e.g. `rustup doc --nomicon`
950
+ // tuple elements: document name used as flag, help message, document index path
951
+ ( "alloc" , "The Rust core allocation and collections library" , "alloc/index.html" ) ,
952
+ ( "book" , "The Rust Programming Language book" , "book/index.html" ) ,
953
+ ( "cargo" , "The Cargo Book" , "cargo/index.html" ) ,
954
+ ( "core" , "The Rust Core Library" , "core/index.html" ) ,
955
+ ( "edition-guide" , "The Rust Edition Guide" , "edition-guide/index.html" ) ,
956
+ ( "nomicon" , "The Dark Arts of Advanced and Unsafe Rust Programming" , "nomicon/index.html" ) ,
957
+ ( "proc_macro" , "A support library for macro authors when defining new macros" , "proc_macro/index.html" ) ,
958
+ ( "reference" , "The Rust Reference" , "reference/index.html" ) ,
959
+ ( "rust-by-example" , "A collection of runnable examples that illustrate various Rust concepts and standard libraries" , "rust-by-example/index.html" ) ,
960
+ ( "rustc" , "The compiler for the Rust programming language" , "rustc/index.html" ) ,
961
+ ( "rustdoc" , "Generate documentation for Rust projects" , "rustdoc/index.html" ) ,
962
+ ( "std" , "Standard library API documentation" , "std/index.html" ) ,
963
+ ( "test" , "Support code for rustc's built in unit-test and micro-benchmarking framework" , "test/index.html" ) ,
964
+ ( "unstable-book" , "The Unstable Book" , "unstable-book/index.html" ) ,
965
+ ] ;
966
+
953
967
fn doc ( cfg : & Cfg , m : & ArgMatches ) -> Result < ( ) > {
954
968
let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
955
- let doc_url = if m. is_present ( "book" ) {
956
- "book/index.html"
957
- } else if m. is_present ( "std" ) {
958
- "std/index.html"
959
- } else if m. is_present ( "reference" ) {
960
- "reference/index.html"
961
- } else {
962
- "index.html"
963
- } ;
969
+
970
+ let doc_url =
971
+ if let Some ( ( _, _, path) ) = DOCS_DATA . into_iter ( ) . find ( |( name, _, _) | m. is_present ( name) ) {
972
+ path
973
+ } else {
974
+ "index.html"
975
+ } ;
964
976
965
977
if m. is_present ( "path" ) {
966
978
let doc_path = toolchain. doc_path ( doc_url) ?;
0 commit comments