refactor: Move from deprecated arg_from_usage

This commit is contained in:
Ed Page 2022-01-19 10:10:53 -06:00
parent a19d91ef37
commit 857ca19fe4
6 changed files with 85 additions and 56 deletions

View File

@ -1,5 +1,5 @@
use crate::{get_book_dir, open}; use crate::{get_book_dir, open};
use clap::{App, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::MDBook; use mdbook::MDBook;
@ -7,16 +7,22 @@ use mdbook::MDBook;
pub fn make_subcommand<'help>() -> App<'help> { pub fn make_subcommand<'help>() -> App<'help> {
App::new("build") App::new("build")
.about("Builds a book from its markdown files") .about("Builds a book from its markdown files")
.arg_from_usage( .arg(
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.help(
"Output directory for the book{n}\
Relative paths are interpreted relative to the book's root directory.{n}\ Relative paths are interpreted relative to the book's root directory.{n}\
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
),
) )
.arg_from_usage( .arg(arg!([dir]
"[dir] 'Root directory for the book{n}\ "Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'", (Defaults to the Current Directory when omitted)"
) ))
.arg_from_usage("-o, --open 'Opens the compiled book in a web browser'") .arg(arg!(-o --open "Opens the compiled book in a web browser"))
} }
// Build command implementation // Build command implementation

View File

@ -1,6 +1,6 @@
use crate::get_book_dir; use crate::get_book_dir;
use anyhow::Context; use anyhow::Context;
use clap::{App, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::MDBook; use mdbook::MDBook;
use std::fs; use std::fs;
@ -8,16 +8,21 @@ use std::fs;
pub fn make_subcommand<'help>() -> App<'help> { pub fn make_subcommand<'help>() -> App<'help> {
App::new("clean") App::new("clean")
.about("Deletes a built book") .about("Deletes a built book")
.arg_from_usage( .arg(
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.help(
"Output directory for the book{n}\
Relative paths are interpreted relative to the book's root directory.{n}\ Relative paths are interpreted relative to the book's root directory.{n}\
Running this command deletes this directory.{n}\ If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", ),
)
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
) )
.arg(arg!([dir]
"Root directory for the book{n}\
(Defaults to the Current Directory when omitted)"
))
} }
// Clean command implementation // Clean command implementation

View File

@ -1,5 +1,5 @@
use crate::get_book_dir; use crate::get_book_dir;
use clap::{App, Arg, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::config; use mdbook::config;
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::MDBook; use mdbook::MDBook;
@ -12,12 +12,12 @@ pub fn make_subcommand<'help>() -> App<'help> {
App::new("init") App::new("init")
.about("Creates the boilerplate structure and files for a new book") .about("Creates the boilerplate structure and files for a new book")
// the {n} denotes a newline which will properly aligned in all help messages // the {n} denotes a newline which will properly aligned in all help messages
.arg_from_usage( .arg(arg!([dir]
"[dir] 'Directory to create the book in{n}\ "Directory to create the book in{n}\
(Defaults to the Current Directory when omitted)'", (Defaults to the Current Directory when omitted)"
) ))
.arg_from_usage("--theme 'Copies the default theme into your source folder'") .arg(arg!(--theme "Copies the default theme into your source folder"))
.arg_from_usage("--force 'Skips confirmation prompts'") .arg(arg!(--force "Skips confirmation prompts"))
.arg( .arg(
Arg::new("title") Arg::new("title")
.long("title") .long("title")

View File

@ -1,7 +1,7 @@
#[cfg(feature = "watch")] #[cfg(feature = "watch")]
use super::watch; use super::watch;
use crate::{get_book_dir, open}; use crate::{get_book_dir, open};
use clap::{App, Arg, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use futures_util::sink::SinkExt; use futures_util::sink::SinkExt;
use futures_util::StreamExt; use futures_util::StreamExt;
use mdbook::errors::*; use mdbook::errors::*;
@ -21,15 +21,21 @@ const LIVE_RELOAD_ENDPOINT: &str = "__livereload";
pub fn make_subcommand<'help>() -> App<'help> { pub fn make_subcommand<'help>() -> App<'help> {
App::new("serve") App::new("serve")
.about("Serves a book at http://localhost:3000, and rebuilds it on changes") .about("Serves a book at http://localhost:3000, and rebuilds it on changes")
.arg_from_usage( .arg(
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.help(
"Output directory for the book{n}\
Relative paths are interpreted relative to the book's root directory.{n}\ Relative paths are interpreted relative to the book's root directory.{n}\
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
) ),
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
) )
.arg(arg!([dir]
"Root directory for the book{n}\
(Defaults to the Current Directory when omitted)"
))
.arg( .arg(
Arg::new("hostname") Arg::new("hostname")
.short('n') .short('n')
@ -48,7 +54,7 @@ pub fn make_subcommand<'help>() -> App<'help> {
.forbid_empty_values(true) .forbid_empty_values(true)
.help("Port to use for HTTP connections"), .help("Port to use for HTTP connections"),
) )
.arg_from_usage("-o, --open 'Opens the book server in a web browser'") .arg(arg!(-o --open "Opens the compiled book in a web browser"))
} }
// Serve command implementation // Serve command implementation

View File

@ -1,5 +1,5 @@
use crate::get_book_dir; use crate::get_book_dir;
use clap::{App, Arg, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::MDBook; use mdbook::MDBook;
@ -7,15 +7,21 @@ use mdbook::MDBook;
pub fn make_subcommand<'help>() -> App<'help> { pub fn make_subcommand<'help>() -> App<'help> {
App::new("test") App::new("test")
.about("Tests that a book's Rust code samples compile") .about("Tests that a book's Rust code samples compile")
.arg_from_usage( .arg(
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.help(
"Output directory for the book{n}\
Relative paths are interpreted relative to the book's root directory.{n}\ Relative paths are interpreted relative to the book's root directory.{n}\
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
) ),
.arg_from_usage(
"[dir] 'Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'",
) )
.arg(arg!([dir]
"Root directory for the book{n}\
(Defaults to the Current Directory when omitted)"
))
.arg(Arg::new("library-path") .arg(Arg::new("library-path")
.short('L') .short('L')
.long("library-path") .long("library-path")

View File

@ -1,5 +1,5 @@
use crate::{get_book_dir, open}; use crate::{get_book_dir, open};
use clap::{App, ArgMatches}; use clap::{arg, App, Arg, ArgMatches};
use mdbook::errors::Result; use mdbook::errors::Result;
use mdbook::utils; use mdbook::utils;
use mdbook::MDBook; use mdbook::MDBook;
@ -13,16 +13,22 @@ use std::time::Duration;
pub fn make_subcommand<'help>() -> App<'help> { pub fn make_subcommand<'help>() -> App<'help> {
App::new("watch") App::new("watch")
.about("Watches a book's files and rebuilds it on changes") .about("Watches a book's files and rebuilds it on changes")
.arg_from_usage( .arg(
"-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Arg::new("dest-dir")
.short('d')
.long("dest-dir")
.value_name("dest-dir")
.help(
"Output directory for the book{n}\
Relative paths are interpreted relative to the book's root directory.{n}\ Relative paths are interpreted relative to the book's root directory.{n}\
If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.",
),
) )
.arg_from_usage( .arg(arg!([dir]
"[dir] 'Root directory for the book{n}\ "Root directory for the book{n}\
(Defaults to the Current Directory when omitted)'", (Defaults to the Current Directory when omitted)"
) ))
.arg_from_usage("-o, --open 'Open the compiled book in a web browser'") .arg(arg!(-o --open "Opens the compiled book in a web browser"))
} }
// Watch command implementation // Watch command implementation