Skip to content

Commit f767b8f

Browse files
authored
Merge pull request #1597 from king6cong/master
Support to open more documents directly in `rustup doc`
2 parents edf7206 + 7e8e72a commit f767b8f

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

src/rustup-cli/rustup_mode.rs

+36-24
Original file line numberDiff line numberDiff line change
@@ -399,28 +399,23 @@ pub fn cli() -> App<'static, 'static> {
399399
.long("path")
400400
.help("Only print the path to the documentation"),
401401
)
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<_>>()
416408
)
417409
.arg(
418410
Arg::with_name("toolchain")
419411
.help(TOOLCHAIN_ARG_HELP)
420412
.long("toolchain")
421413
.takes_value(true),
422414
)
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+
)),
424419
);
425420

426421
if cfg!(not(target_os = "windows")) {
@@ -970,17 +965,34 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
970965
Ok(())
971966
}
972967

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+
973987
fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
974988
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+
};
984996

985997
if m.is_present("path") {
986998
let doc_path = toolchain.doc_path(doc_url)?;

0 commit comments

Comments
 (0)