@@ -399,28 +399,23 @@ pub fn cli() -> App<'static, 'static> {
399
399
. long ( "path" )
400
400
. help ( "Only print the path to the documentation" ) ,
401
401
)
402
- . arg (
403
- Arg :: with_name ( "book" )
404
- . long ( "book" )
405
- . help ( "The Rust Programming Language book" ) ,
406
- )
407
- . arg (
408
- Arg :: with_name ( "std" )
409
- . long ( "std" )
410
- . help ( "Standard library API documentation" ) ,
411
- )
412
- . arg (
413
- Arg :: with_name ( "reference" )
414
- . long ( "reference" )
415
- . help ( "The Rust Reference" ) ,
402
+ . args (
403
+ & DOCS_DATA . into_iter ( ) . map ( |( name, help_msg, _) | {
404
+ Arg :: with_name ( name)
405
+ . long ( name)
406
+ . help ( help_msg)
407
+ } ) . collect :: < Vec < _ > > ( )
416
408
)
417
409
. arg (
418
410
Arg :: with_name ( "toolchain" )
419
411
. help ( TOOLCHAIN_ARG_HELP )
420
412
. long ( "toolchain" )
421
413
. takes_value ( true ) ,
422
414
)
423
- . group ( ArgGroup :: with_name ( "page" ) . args ( & [ "book" , "std" , "reference" ] ) ) ,
415
+ . group ( ArgGroup :: with_name ( "page" ) . args (
416
+ & DOCS_DATA . into_iter ( ) . map ( |( name, _, _) | * name)
417
+ . collect :: < Vec < _ > > ( )
418
+ ) ) ,
424
419
) ;
425
420
426
421
if cfg ! ( not( target_os = "windows" ) ) {
@@ -970,17 +965,34 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
970
965
Ok ( ( ) )
971
966
}
972
967
968
+ const DOCS_DATA : & [ ( & ' static str , & ' static str , & ' static str , ) ] = & [
969
+ // flags can be used to open specific documents, e.g. `rustup doc --nomicon`
970
+ // tuple elements: document name used as flag, help message, document index path
971
+ ( "alloc" , "The Rust core allocation and collections library" , "alloc/index.html" ) ,
972
+ ( "book" , "The Rust Programming Language book" , "book/index.html" ) ,
973
+ ( "cargo" , "The Cargo Book" , "cargo/index.html" ) ,
974
+ ( "core" , "The Rust Core Library" , "core/index.html" ) ,
975
+ ( "edition-guide" , "The Rust Edition Guide" , "edition-guide/index.html" ) ,
976
+ ( "nomicon" , "The Dark Arts of Advanced and Unsafe Rust Programming" , "nomicon/index.html" ) ,
977
+ ( "proc_macro" , "A support library for macro authors when defining new macros" , "proc_macro/index.html" ) ,
978
+ ( "reference" , "The Rust Reference" , "reference/index.html" ) ,
979
+ ( "rust-by-example" , "A collection of runnable examples that illustrate various Rust concepts and standard libraries" , "rust-by-example/index.html" ) ,
980
+ ( "rustc" , "The compiler for the Rust programming language" , "rustc/index.html" ) ,
981
+ ( "rustdoc" , "Generate documentation for Rust projects" , "rustdoc/index.html" ) ,
982
+ ( "std" , "Standard library API documentation" , "std/index.html" ) ,
983
+ ( "test" , "Support code for rustc's built in unit-test and micro-benchmarking framework" , "test/index.html" ) ,
984
+ ( "unstable-book" , "The Unstable Book" , "unstable-book/index.html" ) ,
985
+ ] ;
986
+
973
987
fn doc ( cfg : & Cfg , m : & ArgMatches ) -> Result < ( ) > {
974
988
let toolchain = explicit_or_dir_toolchain ( cfg, m) ?;
975
- let doc_url = if m. is_present ( "book" ) {
976
- "book/index.html"
977
- } else if m. is_present ( "std" ) {
978
- "std/index.html"
979
- } else if m. is_present ( "reference" ) {
980
- "reference/index.html"
981
- } else {
982
- "index.html"
983
- } ;
989
+
990
+ let doc_url =
991
+ if let Some ( ( _, _, path) ) = DOCS_DATA . into_iter ( ) . find ( |( name, _, _) | m. is_present ( name) ) {
992
+ path
993
+ } else {
994
+ "index.html"
995
+ } ;
984
996
985
997
if m. is_present ( "path" ) {
986
998
let doc_path = toolchain. doc_path ( doc_url) ?;
0 commit comments