Skip to content

Commit 7e8e72a

Browse files
committed
Support to open more documents directly in rustup doc
e.g. `rustup doc --nomicon` Documents supported: alloc,book,cargo,core,edition-guide,nomicon,proc_macro,reference,rust-by-example,rustc,rustdoc,std,test,unstable-book
1 parent 25f476d commit 7e8e72a

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
@@ -379,28 +379,23 @@ pub fn cli() -> App<'static, 'static> {
379379
.long("path")
380380
.help("Only print the path to the documentation"),
381381
)
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<_>>()
396388
)
397389
.arg(
398390
Arg::with_name("toolchain")
399391
.help(TOOLCHAIN_ARG_HELP)
400392
.long("toolchain")
401393
.takes_value(true),
402394
)
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+
)),
404399
);
405400

406401
if cfg!(not(target_os = "windows")) {
@@ -950,17 +945,34 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
950945
Ok(())
951946
}
952947

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

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

0 commit comments

Comments
 (0)