Skip to content

Commit b8844f2

Browse files
committed
Bump to clap 3
1 parent 73443a0 commit b8844f2

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,7 @@ dependencies = [
33853385
name = "rustbook"
33863386
version = "0.1.0"
33873387
dependencies = [
3388-
"clap 2.34.0",
3388+
"clap 3.1.1",
33893389
"env_logger 0.7.1",
33903390
"mdbook",
33913391
]

src/tools/rustbook/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT OR Apache-2.0"
55
edition = "2021"
66

77
[dependencies]
8-
clap = "2.25.0"
8+
clap = "3.1.1"
99
env_logger = "0.7.1"
1010

1111
[dependencies.mdbook]

src/tools/rustbook/src/main.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,55 @@ use clap::crate_version;
33
use std::env;
44
use std::path::{Path, PathBuf};
55

6-
use clap::{App, AppSettings, ArgMatches, SubCommand};
6+
use clap::{arg, ArgMatches, Command};
77

88
use mdbook::errors::Result as Result3;
99
use mdbook::MDBook;
1010

1111
fn main() {
12+
let crate_version = format!("v{}", crate_version!());
1213
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
13-
let d_message = "-d, --dest-dir=[dest-dir]
14-
'The output directory for your book{n}(Defaults to ./book when omitted)'";
15-
let dir_message = "[dir]
16-
'A directory for your book{n}(Defaults to Current Directory when omitted)'";
14+
let d_arg = arg!(-d --"dest-dir" <DEST_DIR>
15+
"The output directory for your book{n}(Defaults to ./book when omitted)");
16+
let dir_arg = arg!([dir]
17+
"A directory for your book{n}(Defaults to Current Directory when omitted)");
1718

18-
let matches = App::new("rustbook")
19+
let matches = Command::new("rustbook")
1920
.about("Build a book with mdBook")
2021
.author("Steve Klabnik <[email protected]>")
21-
.version(&*format!("v{}", crate_version!()))
22-
.setting(AppSettings::SubcommandRequired)
22+
.version(&*crate_version)
23+
.subcommand_required(true)
2324
.subcommand(
24-
SubCommand::with_name("build")
25+
Command::new("build")
2526
.about("Build the book from the markdown files")
26-
.arg_from_usage(d_message)
27-
.arg_from_usage(dir_message),
27+
.arg(d_arg)
28+
.arg(&dir_arg),
2829
)
2930
.subcommand(
30-
SubCommand::with_name("test")
31+
Command::new("test")
3132
.about("Tests that a book's Rust code samples compile")
32-
.arg_from_usage(dir_message),
33+
.arg(dir_arg),
3334
)
3435
.get_matches();
3536

3637
// Check which subcomamnd the user ran...
3738
match matches.subcommand() {
38-
("build", Some(sub_matches)) => {
39+
Some(("build", sub_matches)) => {
3940
if let Err(e) = build(sub_matches) {
4041
handle_error(e);
4142
}
4243
}
43-
("test", Some(sub_matches)) => {
44+
Some(("test", sub_matches)) => {
4445
if let Err(e) = test(sub_matches) {
4546
handle_error(e);
4647
}
4748
}
48-
(_, _) => unreachable!(),
49+
_ => unreachable!(),
4950
};
5051
}
5152

5253
// Build command implementation
53-
pub fn build(args: &ArgMatches<'_>) -> Result3<()> {
54+
pub fn build(args: &ArgMatches) -> Result3<()> {
5455
let book_dir = get_book_dir(args);
5556
let mut book = load_book(&book_dir)?;
5657

@@ -66,13 +67,13 @@ pub fn build(args: &ArgMatches<'_>) -> Result3<()> {
6667
Ok(())
6768
}
6869

69-
fn test(args: &ArgMatches<'_>) -> Result3<()> {
70+
fn test(args: &ArgMatches) -> Result3<()> {
7071
let book_dir = get_book_dir(args);
7172
let mut book = load_book(&book_dir)?;
7273
book.test(vec![])
7374
}
7475

75-
fn get_book_dir(args: &ArgMatches<'_>) -> PathBuf {
76+
fn get_book_dir(args: &ArgMatches) -> PathBuf {
7677
if let Some(dir) = args.value_of("dir") {
7778
// Check if path is relative from current dir, or absolute...
7879
let p = Path::new(dir);

0 commit comments

Comments
 (0)