1
Fork 0

Simplify command-line-argument declarations in librustdoc

This commit is contained in:
Zalathar 2024-11-07 23:27:20 +11:00
parent 001013c63c
commit b8377e5844
2 changed files with 463 additions and 472 deletions

View file

@ -1411,20 +1411,6 @@ impl RustcOptGroup {
pub fn apply(&self, options: &mut getopts::Options) { pub fn apply(&self, options: &mut getopts::Options) {
(self.apply)(options); (self.apply)(options);
} }
pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
where
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Stable }
}
pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
where
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Unstable }
}
} }
pub fn make_opt( pub fn make_opt(

View file

@ -215,220 +215,223 @@ fn init_logging(early_dcx: &EarlyDiagCtxt) {
} }
fn opts() -> Vec<RustcOptGroup> { fn opts() -> Vec<RustcOptGroup> {
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable; use rustc_session::config::OptionKind::{Flag, FlagMulti, Multi, Opt};
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable; use rustc_session::config::OptionStability::{Stable, Unstable};
use rustc_session::config::make_opt as opt;
vec![ vec![
stable("h", |o| o.optflagmulti("h", "help", "show this help message")), opt(Stable, FlagMulti, "h", "help", "show this help message", ""),
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")), opt(Stable, FlagMulti, "V", "version", "print rustdoc's version", ""),
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")), opt(Stable, FlagMulti, "v", "verbose", "use verbose output", ""),
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")), opt(Stable, Opt, "w", "output-format", "the output type to write", "[html]"),
stable("output", |o| { opt(
o.optopt( Stable,
Opt,
"", "",
"output", "output",
"Which directory to place the output. \ "Which directory to place the output. This option is deprecated, use --out-dir instead.",
This option is deprecated, use --out-dir instead.",
"PATH", "PATH",
) ),
}), opt(Stable, Opt, "o", "out-dir", "which directory to place the output", "PATH"),
stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")), opt(Stable, Opt, "", "crate-name", "specify the name of this crate", "NAME"),
stable("crate-name", |o| {
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
}),
make_crate_type_option(), make_crate_type_option(),
stable("L", |o| { opt(Stable, Multi, "L", "library-path", "directory to add to crate search path", "DIR"),
o.optmulti("L", "library-path", "directory to add to crate search path", "DIR") opt(Stable, Multi, "", "cfg", "pass a --cfg to rustc", ""),
}), opt(Stable, Multi, "", "check-cfg", "pass a --check-cfg to rustc", ""),
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")), opt(Stable, Multi, "", "extern", "pass an --extern to rustc", "NAME[=PATH]"),
stable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")), opt(
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")), Unstable,
unstable("extern-html-root-url", |o| { Multi,
o.optmulti(
"", "",
"extern-html-root-url", "extern-html-root-url",
"base URL to use for dependencies; for example, \ "base URL to use for dependencies; for example, \
\"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html", \"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html",
"NAME=URL", "NAME=URL",
) ),
}), opt(
unstable("extern-html-root-takes-precedence", |o| { Unstable,
o.optflagmulti( FlagMulti,
"", "",
"extern-html-root-takes-precedence", "extern-html-root-takes-precedence",
"give precedence to `--extern-html-root-url`, not `html_root_url`", "give precedence to `--extern-html-root-url`, not `html_root_url`",
) "",
}), ),
stable("C", |o| { opt(Stable, Multi, "C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]"),
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]") opt(Stable, FlagMulti, "", "document-private-items", "document private items", ""),
}), opt(
stable("document-private-items", |o| { Unstable,
o.optflagmulti("", "document-private-items", "document private items") FlagMulti,
}), "",
unstable("document-hidden-items", |o| { "document-hidden-items",
o.optflagmulti("", "document-hidden-items", "document items that have doc(hidden)") "document items that have doc(hidden)",
}), "",
stable("test", |o| o.optflagmulti("", "test", "run code examples as tests")), ),
stable("test-args", |o| { opt(Stable, FlagMulti, "", "test", "run code examples as tests", ""),
o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS") opt(Stable, Multi, "", "test-args", "arguments to pass to the test runner", "ARGS"),
}), opt(
stable("test-run-directory", |o| { Stable,
o.optopt( Opt,
"", "",
"test-run-directory", "test-run-directory",
"The working directory in which to run tests", "The working directory in which to run tests",
"PATH", "PATH",
) ),
}), opt(Stable, Opt, "", "target", "target triple to document", "TRIPLE"),
stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")), opt(
stable("markdown-css", |o| { Stable,
o.optmulti( Multi,
"", "",
"markdown-css", "markdown-css",
"CSS files to include via <link> in a rendered Markdown file", "CSS files to include via <link> in a rendered Markdown file",
"FILES", "FILES",
) ),
}), opt(
stable("html-in-header", |o| { Stable,
o.optmulti( Multi,
"", "",
"html-in-header", "html-in-header",
"files to include inline in the <head> section of a rendered Markdown file \ "files to include inline in the <head> section of a rendered Markdown file \
or generated documentation", or generated documentation",
"FILES", "FILES",
) ),
}), opt(
stable("html-before-content", |o| { Stable,
o.optmulti( Multi,
"", "",
"html-before-content", "html-before-content",
"files to include inline between <body> and the content of a rendered \ "files to include inline between <body> and the content of a rendered \
Markdown file or generated documentation", Markdown file or generated documentation",
"FILES", "FILES",
) ),
}), opt(
stable("html-after-content", |o| { Stable,
o.optmulti( Multi,
"", "",
"html-after-content", "html-after-content",
"files to include inline between the content and </body> of a rendered \ "files to include inline between the content and </body> of a rendered \
Markdown file or generated documentation", Markdown file or generated documentation",
"FILES", "FILES",
) ),
}), opt(
unstable("markdown-before-content", |o| { Unstable,
o.optmulti( Multi,
"", "",
"markdown-before-content", "markdown-before-content",
"files to include inline between <body> and the content of a rendered \ "files to include inline between <body> and the content of a rendered \
Markdown file or generated documentation", Markdown file or generated documentation",
"FILES", "FILES",
) ),
}), opt(
unstable("markdown-after-content", |o| { Unstable,
o.optmulti( Multi,
"", "",
"markdown-after-content", "markdown-after-content",
"files to include inline between the content and </body> of a rendered \ "files to include inline between the content and </body> of a rendered \
Markdown file or generated documentation", Markdown file or generated documentation",
"FILES", "FILES",
) ),
}), opt(Stable, Opt, "", "markdown-playground-url", "URL to send code snippets to", "URL"),
stable("markdown-playground-url", |o| { opt(Stable, FlagMulti, "", "markdown-no-toc", "don't include table of contents", ""),
o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL") opt(
}), Stable,
stable("markdown-no-toc", |o| { Opt,
o.optflagmulti("", "markdown-no-toc", "don't include table of contents")
}),
stable("e", |o| {
o.optopt(
"e", "e",
"extend-css", "extend-css",
"To add some CSS rules with a given file to generate doc with your \ "To add some CSS rules with a given file to generate doc with your own theme. \
own theme. However, your theme might break if the rustdoc's generated HTML \ However, your theme might break if the rustdoc's generated HTML changes, so be careful!",
changes, so be careful!",
"PATH", "PATH",
) ),
}), opt(
unstable("Z", |o| { Unstable,
o.optmulti("Z", "", "unstable / perma-unstable options (only on nightly build)", "FLAG") Multi,
}), "Z",
stable("sysroot", |o| o.optopt("", "sysroot", "Override the system root", "PATH")), "",
unstable("playground-url", |o| { "unstable / perma-unstable options (only on nightly build)",
o.optopt( "FLAG",
),
opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
opt(
Unstable,
Opt,
"", "",
"playground-url", "playground-url",
"URL to send code snippets to, may be reset by --markdown-playground-url \ "URL to send code snippets to, may be reset by --markdown-playground-url \
or `#![doc(html_playground_url=...)]`", or `#![doc(html_playground_url=...)]`",
"URL", "URL",
) ),
}), opt(
unstable("display-doctest-warnings", |o| { Unstable,
o.optflagmulti( FlagMulti,
"", "",
"display-doctest-warnings", "display-doctest-warnings",
"show warnings that originate in doctests", "show warnings that originate in doctests",
) "",
}), ),
stable("crate-version", |o| { opt(
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION") Stable,
}), Opt,
unstable("sort-modules-by-appearance", |o| { "",
o.optflagmulti( "crate-version",
"crate version to print into documentation",
"VERSION",
),
opt(
Unstable,
FlagMulti,
"", "",
"sort-modules-by-appearance", "sort-modules-by-appearance",
"sort modules by where they appear in the program, rather than alphabetically", "sort modules by where they appear in the program, rather than alphabetically",
) "",
}), ),
stable("default-theme", |o| { opt(
o.optopt( Stable,
Opt,
"", "",
"default-theme", "default-theme",
"Set the default theme. THEME should be the theme name, generally lowercase. \ "Set the default theme. THEME should be the theme name, generally lowercase. \
If an unknown default theme is specified, the builtin default is used. \ If an unknown default theme is specified, the builtin default is used. \
The set of themes, and the rustdoc built-in default, are not stable.", The set of themes, and the rustdoc built-in default, are not stable.",
"THEME", "THEME",
) ),
}), opt(
unstable("default-setting", |o| { Unstable,
o.optmulti( Multi,
"", "",
"default-setting", "default-setting",
"Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \ "Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \
from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \ from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \
Supported SETTINGs and VALUEs are not documented and not stable.", Supported SETTINGs and VALUEs are not documented and not stable.",
"SETTING[=VALUE]", "SETTING[=VALUE]",
) ),
}), opt(
stable("theme", |o| { Stable,
o.optmulti( Multi,
"", "",
"theme", "theme",
"additional themes which will be added to the generated docs", "additional themes which will be added to the generated docs",
"FILES", "FILES",
) ),
}), opt(Stable, Multi, "", "check-theme", "check if given theme is valid", "FILES"),
stable("check-theme", |o| { opt(
o.optmulti("", "check-theme", "check if given theme is valid", "FILES") Unstable,
}), Opt,
unstable("resource-suffix", |o| {
o.optopt(
"", "",
"resource-suffix", "resource-suffix",
"suffix to add to CSS and JavaScript files, e.g., \"search-index.js\" will \ "suffix to add to CSS and JavaScript files, \
become \"search-index-suffix.js\"", e.g., \"search-index.js\" will become \"search-index-suffix.js\"",
"PATH", "PATH",
) ),
}), opt(
stable("edition", |o| { Stable,
o.optopt( Opt,
"", "",
"edition", "edition",
"edition to use when compiling rust code (default: 2015)", "edition to use when compiling rust code (default: 2015)",
"EDITION", "EDITION",
) ),
}), opt(
stable("color", |o| { Stable,
o.optopt( Opt,
"", "",
"color", "color",
"Configure coloring of output: "Configure coloring of output:
@ -436,249 +439,251 @@ fn opts() -> Vec<RustcOptGroup> {
always = always colorize output; always = always colorize output;
never = never colorize output", never = never colorize output",
"auto|always|never", "auto|always|never",
) ),
}), opt(
stable("error-format", |o| { Stable,
o.optopt( Opt,
"", "",
"error-format", "error-format",
"How errors and other messages are produced", "How errors and other messages are produced",
"human|json|short", "human|json|short",
) ),
}), opt(
stable("diagnostic-width", |o| { Stable,
o.optopt( Opt,
"", "",
"diagnostic-width", "diagnostic-width",
"Provide width of the output for truncated error messages", "Provide width of the output for truncated error messages",
"WIDTH", "WIDTH",
) ),
}), opt(Stable, Opt, "", "json", "Configure the structure of JSON diagnostics", "CONFIG"),
stable("json", |o| { opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG") opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
}), opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")), opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")), opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")), opt(
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")), Stable,
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")), Multi,
stable("cap-lints", |o| {
o.optmulti(
"", "",
"cap-lints", "cap-lints",
"Set the most restrictive lint level. \ "Set the most restrictive lint level. \
More restrictive lints are capped at this \ More restrictive lints are capped at this level. \
level. By default, it is at `forbid` level.", By default, it is at `forbid` level.",
"LEVEL", "LEVEL",
) ),
}), opt(Unstable, Opt, "", "index-page", "Markdown file to be used as index page", "PATH"),
unstable("index-page", |o| { opt(
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH") Unstable,
}), FlagMulti,
unstable("enable-index-page", |o| { "",
o.optflagmulti("", "enable-index-page", "To enable generation of the index page") "enable-index-page",
}), "To enable generation of the index page",
unstable("static-root-path", |o| { "",
o.optopt( ),
opt(
Unstable,
Opt,
"", "",
"static-root-path", "static-root-path",
"Path string to force loading static files from in output pages. \ "Path string to force loading static files from in output pages. \
If not set, uses combinations of '../' to reach the documentation root.", If not set, uses combinations of '../' to reach the documentation root.",
"PATH", "PATH",
) ),
}), opt(
unstable("persist-doctests", |o| { Unstable,
o.optopt( Opt,
"", "",
"persist-doctests", "persist-doctests",
"Directory to persist doctest executables into", "Directory to persist doctest executables into",
"PATH", "PATH",
) ),
}), opt(
unstable("show-coverage", |o| { Unstable,
o.optflagmulti( FlagMulti,
"", "",
"show-coverage", "show-coverage",
"calculate percentage of public items with documentation", "calculate percentage of public items with documentation",
) "",
}), ),
unstable("enable-per-target-ignores", |o| { opt(
o.optflagmulti( Unstable,
FlagMulti,
"", "",
"enable-per-target-ignores", "enable-per-target-ignores",
"parse ignore-foo for ignoring doctests on a per-target basis", "parse ignore-foo for ignoring doctests on a per-target basis",
) "",
}), ),
unstable("runtool", |o| { opt(
o.optopt( Unstable,
Opt,
"", "",
"runtool", "runtool",
"", "",
"The tool to run tests with when building for a different target than host", "The tool to run tests with when building for a different target than host",
) ),
}), opt(
unstable("runtool-arg", |o| { Unstable,
o.optmulti( Multi,
"", "",
"runtool-arg", "runtool-arg",
"", "",
"One (of possibly many) arguments to pass to the runtool", "One (of possibly many) arguments to pass to the runtool",
) ),
}), opt(
unstable("test-builder", |o| { Unstable,
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH") Opt,
}), "",
unstable("test-builder-wrapper", |o| { "test-builder",
o.optmulti( "The rustc-like binary to use as the test builder",
"PATH",
),
opt(
Unstable,
Multi,
"", "",
"test-builder-wrapper", "test-builder-wrapper",
"Wrapper program to pass test-builder and arguments", "Wrapper program to pass test-builder and arguments",
"PATH", "PATH",
) ),
}), opt(Unstable, FlagMulti, "", "check", "Run rustdoc checks", ""),
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")), opt(
unstable("generate-redirect-map", |o| { Unstable,
o.optflagmulti( FlagMulti,
"", "",
"generate-redirect-map", "generate-redirect-map",
"Generate JSON file at the top level instead of generating HTML redirection files", "Generate JSON file at the top level instead of generating HTML redirection files",
) "",
}), ),
unstable("emit", |o| { opt(
o.optmulti( Unstable,
Multi,
"", "",
"emit", "emit",
"Comma separated list of types of output for rustdoc to emit", "Comma separated list of types of output for rustdoc to emit",
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
) ),
}), opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""),
unstable("no-run", |o| { opt(
o.optflagmulti("", "no-run", "Compile doctests without running them") Unstable,
}), Multi,
unstable("remap-path-prefix", |o| {
o.optmulti(
"", "",
"remap-path-prefix", "remap-path-prefix",
"Remap source names in compiler messages", "Remap source names in compiler messages",
"FROM=TO", "FROM=TO",
) ),
}), opt(
unstable("show-type-layout", |o| { Unstable,
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs") FlagMulti,
}), "",
unstable("nocapture", |o| { "show-type-layout",
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests") "Include the memory layout of types in the docs",
}), "",
unstable("generate-link-to-definition", |o| { ),
o.optflag( opt(Unstable, Flag, "", "nocapture", "Don't capture stdout and stderr of tests", ""),
opt(
Unstable,
Flag,
"", "",
"generate-link-to-definition", "generate-link-to-definition",
"Make the identifiers in the HTML source code pages navigable", "Make the identifiers in the HTML source code pages navigable",
) "",
}), ),
unstable("scrape-examples-output-path", |o| { opt(
o.optopt( Unstable,
Opt,
"", "",
"scrape-examples-output-path", "scrape-examples-output-path",
"", "",
"collect function call information and output at the given path", "collect function call information and output at the given path",
) ),
}), opt(
unstable("scrape-examples-target-crate", |o| { Unstable,
o.optmulti( Multi,
"", "",
"scrape-examples-target-crate", "scrape-examples-target-crate",
"", "",
"collect function call information for functions from the target crate", "collect function call information for functions from the target crate",
) ),
}), opt(Unstable, Flag, "", "scrape-tests", "Include test code when scraping examples", ""),
unstable("scrape-tests", |o| { opt(
o.optflag("", "scrape-tests", "Include test code when scraping examples") Unstable,
}), Multi,
unstable("with-examples", |o| {
o.optmulti(
"", "",
"with-examples", "with-examples",
"", "",
"path to function call information (for displaying examples in the documentation)", "path to function call information (for displaying examples in the documentation)",
) ),
}), opt(
unstable("merge", |o| { Unstable,
o.optopt( Opt,
"", "",
"merge", "merge",
"Controls how rustdoc handles files from previously documented crates in the doc root "Controls how rustdoc handles files from previously documented crates in the doc root\n\
none = Do not write cross-crate information to the --out-dir none = Do not write cross-crate information to the --out-dir\n\
shared = Append current crate's info to files found in the --out-dir shared = Append current crate's info to files found in the --out-dir\n\
finalize = Write current crate's info and --include-parts-dir info to the --out-dir, overwriting conflicting files", finalize = Write current crate's info and --include-parts-dir info to the --out-dir, overwriting conflicting files",
"none|shared|finalize", "none|shared|finalize",
) ),
}), opt(
unstable("parts-out-dir", |o| { Unstable,
o.optopt( Opt,
"", "",
"parts-out-dir", "parts-out-dir",
"Writes trait implementations and other info for the current crate to provided path. Only use with --merge=none", "Writes trait implementations and other info for the current crate to provided path. Only use with --merge=none",
"path/to/doc.parts/<crate-name>", "path/to/doc.parts/<crate-name>",
) ),
}), opt(
unstable("include-parts-dir", |o| { Unstable,
o.optmulti( Multi,
"", "",
"include-parts-dir", "include-parts-dir",
"Includes trait implementations and other crate info from provided path. Only use with --merge=finalize", "Includes trait implementations and other crate info from provided path. Only use with --merge=finalize",
"path/to/doc.parts/<crate-name>", "path/to/doc.parts/<crate-name>",
) ),
}),
// deprecated / removed options // deprecated / removed options
unstable("disable-minification", |o| o.optflagmulti("", "disable-minification", "removed")), opt(Unstable, FlagMulti, "", "disable-minification", "removed", ""),
stable("plugin-path", |o| { opt(
o.optmulti( Stable,
Multi,
"", "",
"plugin-path", "plugin-path",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information",
"DIR", "DIR",
) ),
}), opt(
stable("passes", |o| { Stable,
o.optmulti( Multi,
"", "",
"passes", "passes",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information",
"PASSES", "PASSES",
) ),
}), opt(
stable("plugins", |o| { Stable,
o.optmulti( Multi,
"", "",
"plugins", "plugins",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information",
"PLUGINS", "PLUGINS",
) ),
}), opt(
stable("no-default", |o| { Stable,
o.optflagmulti( FlagMulti,
"", "",
"no-defaults", "no-defaults",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information", "",
) ),
}), opt(
stable("r", |o| { Stable,
o.optopt( Opt,
"r", "r",
"input-format", "input-format",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information",
"[rust]", "[rust]",
) ),
}), opt(Unstable, Flag, "", "html-no-source", "Disable HTML source code pages generation", ""),
unstable("html-no-source", |o| {
o.optflag("", "html-no-source", "Disable HTML source code pages generation")
}),
] ]
} }