Skip to content

Commit 857ca19

Browse files
committed
refactor: Move from deprecated arg_from_usage
1 parent a19d91e commit 857ca19

File tree

6 files changed

+85
-56
lines changed

6 files changed

+85
-56
lines changed

src/cmd/build.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
use crate::{get_book_dir, open};
2-
use clap::{App, ArgMatches};
2+
use clap::{arg, App, Arg, ArgMatches};
33
use mdbook::errors::Result;
44
use mdbook::MDBook;
55

66
// Create clap subcommand arguments
77
pub fn make_subcommand<'help>() -> App<'help> {
88
App::new("build")
99
.about("Builds a book from its markdown files")
10-
.arg_from_usage(
11-
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\
12-
Relative paths are interpreted relative to the book's root directory.{n}\
13-
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
10+
.arg(
11+
Arg::new("dest-dir")
12+
.short('d')
13+
.long("dest-dir")
14+
.value_name("dest-dir")
15+
.help(
16+
"Output directory for the book{n}\
17+
Relative paths are interpreted relative to the book's root directory.{n}\
18+
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
19+
),
1420
)
15-
.arg_from_usage(
16-
"[dir] 'Root directory for the book{n}\
17-
(Defaults to the Current Directory when omitted)'",
18-
)
19-
.arg_from_usage("-o, --open 'Opens the compiled book in a web browser'")
21+
.arg(arg!([dir]
22+
"Root directory for the book{n}\
23+
(Defaults to the Current Directory when omitted)"
24+
))
25+
.arg(arg!(-o --open "Opens the compiled book in a web browser"))
2026
}
2127

2228
// Build command implementation

src/cmd/clean.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
use crate::get_book_dir;
22
use anyhow::Context;
3-
use clap::{App, ArgMatches};
3+
use clap::{arg, App, Arg, ArgMatches};
44
use mdbook::MDBook;
55
use std::fs;
66

77
// Create clap subcommand arguments
88
pub fn make_subcommand<'help>() -> App<'help> {
99
App::new("clean")
1010
.about("Deletes a built book")
11-
.arg_from_usage(
12-
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\
13-
Relative paths are interpreted relative to the book's root directory.{n}\
14-
Running this command deletes this directory.{n}\
15-
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
16-
)
17-
.arg_from_usage(
18-
"[dir] 'Root directory for the book{n}\
19-
(Defaults to the Current Directory when omitted)'",
11+
.arg(
12+
Arg::new("dest-dir")
13+
.short('d')
14+
.long("dest-dir")
15+
.value_name("dest-dir")
16+
.help(
17+
"Output directory for the book{n}\
18+
Relative paths are interpreted relative to the book's root directory.{n}\
19+
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
20+
),
2021
)
22+
.arg(arg!([dir]
23+
"Root directory for the book{n}\
24+
(Defaults to the Current Directory when omitted)"
25+
))
2126
}
2227

2328
// Clean command implementation

src/cmd/init.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::get_book_dir;
2-
use clap::{App, Arg, ArgMatches};
2+
use clap::{arg, App, Arg, ArgMatches};
33
use mdbook::config;
44
use mdbook::errors::Result;
55
use mdbook::MDBook;
@@ -12,12 +12,12 @@ pub fn make_subcommand<'help>() -> App<'help> {
1212
App::new("init")
1313
.about("Creates the boilerplate structure and files for a new book")
1414
// the {n} denotes a newline which will properly aligned in all help messages
15-
.arg_from_usage(
16-
"[dir] 'Directory to create the book in{n}\
17-
(Defaults to the Current Directory when omitted)'",
18-
)
19-
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
20-
.arg_from_usage("--force 'Skips confirmation prompts'")
15+
.arg(arg!([dir]
16+
"Directory to create the book in{n}\
17+
(Defaults to the Current Directory when omitted)"
18+
))
19+
.arg(arg!(--theme "Copies the default theme into your source folder"))
20+
.arg(arg!(--force "Skips confirmation prompts"))
2121
.arg(
2222
Arg::new("title")
2323
.long("title")

src/cmd/serve.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "watch")]
22
use super::watch;
33
use crate::{get_book_dir, open};
4-
use clap::{App, Arg, ArgMatches};
4+
use clap::{arg, App, Arg, ArgMatches};
55
use futures_util::sink::SinkExt;
66
use futures_util::StreamExt;
77
use mdbook::errors::*;
@@ -21,15 +21,21 @@ const LIVE_RELOAD_ENDPOINT: &str = "__livereload";
2121
pub fn make_subcommand<'help>() -> App<'help> {
2222
App::new("serve")
2323
.about("Serves a book at http://localhost:3000, and rebuilds it on changes")
24-
.arg_from_usage(
25-
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\
26-
Relative paths are interpreted relative to the book's root directory.{n}\
27-
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
28-
)
29-
.arg_from_usage(
30-
"[dir] 'Root directory for the book{n}\
31-
(Defaults to the Current Directory when omitted)'",
24+
.arg(
25+
Arg::new("dest-dir")
26+
.short('d')
27+
.long("dest-dir")
28+
.value_name("dest-dir")
29+
.help(
30+
"Output directory for the book{n}\
31+
Relative paths are interpreted relative to the book's root directory.{n}\
32+
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
33+
),
3234
)
35+
.arg(arg!([dir]
36+
"Root directory for the book{n}\
37+
(Defaults to the Current Directory when omitted)"
38+
))
3339
.arg(
3440
Arg::new("hostname")
3541
.short('n')
@@ -48,7 +54,7 @@ pub fn make_subcommand<'help>() -> App<'help> {
4854
.forbid_empty_values(true)
4955
.help("Port to use for HTTP connections"),
5056
)
51-
.arg_from_usage("-o, --open 'Opens the book server in a web browser'")
57+
.arg(arg!(-o --open "Opens the compiled book in a web browser"))
5258
}
5359

5460
// Serve command implementation

src/cmd/test.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
use crate::get_book_dir;
2-
use clap::{App, Arg, ArgMatches};
2+
use clap::{arg, App, Arg, ArgMatches};
33
use mdbook::errors::Result;
44
use mdbook::MDBook;
55

66
// Create clap subcommand arguments
77
pub fn make_subcommand<'help>() -> App<'help> {
88
App::new("test")
99
.about("Tests that a book's Rust code samples compile")
10-
.arg_from_usage(
11-
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\
12-
Relative paths are interpreted relative to the book's root directory.{n}\
13-
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
14-
)
15-
.arg_from_usage(
16-
"[dir] 'Root directory for the book{n}\
17-
(Defaults to the Current Directory when omitted)'",
10+
.arg(
11+
Arg::new("dest-dir")
12+
.short('d')
13+
.long("dest-dir")
14+
.value_name("dest-dir")
15+
.help(
16+
"Output directory for the book{n}\
17+
Relative paths are interpreted relative to the book's root directory.{n}\
18+
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
19+
),
1820
)
21+
.arg(arg!([dir]
22+
"Root directory for the book{n}\
23+
(Defaults to the Current Directory when omitted)"
24+
))
1925
.arg(Arg::new("library-path")
2026
.short('L')
2127
.long("library-path")

src/cmd/watch.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{get_book_dir, open};
2-
use clap::{App, ArgMatches};
2+
use clap::{arg, App, Arg, ArgMatches};
33
use mdbook::errors::Result;
44
use mdbook::utils;
55
use mdbook::MDBook;
@@ -13,16 +13,22 @@ use std::time::Duration;
1313
pub fn make_subcommand<'help>() -> App<'help> {
1414
App::new("watch")
1515
.about("Watches a book's files and rebuilds it on changes")
16-
.arg_from_usage(
17-
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\
18-
Relative paths are interpreted relative to the book's root directory.{n}\
19-
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'",
16+
.arg(
17+
Arg::new("dest-dir")
18+
.short('d')
19+
.long("dest-dir")
20+
.value_name("dest-dir")
21+
.help(
22+
"Output directory for the book{n}\
23+
Relative paths are interpreted relative to the book's root directory.{n}\
24+
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
25+
),
2026
)
21-
.arg_from_usage(
22-
"[dir] 'Root directory for the book{n}\
23-
(Defaults to the Current Directory when omitted)'",
24-
)
25-
.arg_from_usage("-o, --open 'Open the compiled book in a web browser'")
27+
.arg(arg!([dir]
28+
"Root directory for the book{n}\
29+
(Defaults to the Current Directory when omitted)"
30+
))
31+
.arg(arg!(-o --open "Opens the compiled book in a web browser"))
2632
}
2733

2834
// Watch command implementation

0 commit comments

Comments
 (0)