Skip to content

Commit 91491fb

Browse files
committed
cargo-rbmt: extend docs with the often use --open arg
1 parent 50667c9 commit 91491fb

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

cargo-rbmt/justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ _default:
2020
@rbmt *args: toolchains
2121
RBMT_LOG_LEVEL=quiet cargo rbmt {{args}}
2222

23+
# Build and open docs.
24+
@docs: (rbmt "docsrs --open")
25+
2326
# Format files.
2427
@fmt: (rbmt "fmt")
2528

cargo-rbmt/src/docs.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::toolchain::{prepare_toolchain, Toolchain};
1010
///
1111
/// This verifies that `cargo doc` works correctly for users with stable Rust.
1212
/// Uses basic rustdoc warnings to catch common documentation issues.
13-
pub fn run(sh: &Shell, packages: &[Package]) -> Result<(), Box<dyn std::error::Error>> {
13+
pub fn run(sh: &Shell, packages: &[Package], open: bool) -> Result<(), Box<dyn std::error::Error>> {
1414
prepare_toolchain(sh, Toolchain::Stable)?;
1515

1616
let mut cmd = quiet_cmd!(sh, "cargo --locked doc --all-features --no-deps");
@@ -20,6 +20,10 @@ pub fn run(sh: &Shell, packages: &[Package]) -> Result<(), Box<dyn std::error::E
2020
cmd = cmd.args(&["-p", &package.id]);
2121
}
2222

23+
if open {
24+
cmd = cmd.arg("--open");
25+
}
26+
2327
cmd.env("RUSTDOCFLAGS", "-D warnings").run()?;
2428

2529
Ok(())
@@ -29,7 +33,11 @@ pub fn run(sh: &Shell, packages: &[Package]) -> Result<(), Box<dyn std::error::E
2933
///
3034
/// This emulates the docs.rs build environment by using the nightly toolchain
3135
/// with `--cfg docsrs` enabled. This catches docs.rs-specific issues.
32-
pub fn run_docsrs(sh: &Shell, packages: &[Package]) -> Result<(), Box<dyn std::error::Error>> {
36+
pub fn run_docsrs(
37+
sh: &Shell,
38+
packages: &[Package],
39+
open: bool,
40+
) -> Result<(), Box<dyn std::error::Error>> {
3341
prepare_toolchain(sh, Toolchain::Nightly)?;
3442

3543
let mut cmd = quiet_cmd!(sh, "cargo --locked doc --all-features --no-deps");
@@ -39,6 +47,10 @@ pub fn run_docsrs(sh: &Shell, packages: &[Package]) -> Result<(), Box<dyn std::e
3947
cmd = cmd.args(&["-p", &package.id]);
4048
}
4149

50+
if open {
51+
cmd = cmd.arg("--open");
52+
}
53+
4254
cmd.env("RUSTDOCFLAGS", "--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links").run()?;
4355

4456
Ok(())

cargo-rbmt/src/main.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@ enum Commands {
5454
/// Run the linter (clippy) for workspace and all crates.
5555
Lint,
5656
/// Build documentation with stable toolchain.
57-
Docs,
57+
Docs {
58+
/// Open documentation in browser after building.
59+
#[arg(long)]
60+
open: bool,
61+
},
5862
/// Build documentation with nightly toolchain for docs.rs.
59-
Docsrs,
63+
Docsrs {
64+
/// Open documentation in browser after building.
65+
#[arg(long)]
66+
open: bool,
67+
},
6068
/// Run benchmark tests for all crates.
6169
Bench,
6270
/// Run tests with specified toolchain.
@@ -164,13 +172,13 @@ fn main() {
164172
eprintln!("Error running lint task: {}", e);
165173
process::exit(1);
166174
},
167-
Commands::Docs =>
168-
if let Err(e) = docs::run(&sh, &packages) {
175+
Commands::Docs { open } =>
176+
if let Err(e) = docs::run(&sh, &packages, open) {
169177
eprintln!("Error building docs: {}", e);
170178
process::exit(1);
171179
},
172-
Commands::Docsrs =>
173-
if let Err(e) = docs::run_docsrs(&sh, &packages) {
180+
Commands::Docsrs { open } =>
181+
if let Err(e) = docs::run_docsrs(&sh, &packages, open) {
174182
eprintln!("Error building docs.rs docs: {}", e);
175183
process::exit(1);
176184
},

0 commit comments

Comments
 (0)