Skip to content

Commit 382fc41

Browse files
prertikbudziq
authored andcommitted
run rustfmt on the repository #398(Updated) (#438)
rustfmt the repository #398
1 parent b45e5e4 commit 382fc41

32 files changed

+738
-689
lines changed

build.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,31 @@ error_chain!{
3232
}
3333

3434
fn program_exists(program: &str) -> Result<()> {
35-
execs::cmd(program)
36-
.arg("-v")
37-
.output()
38-
.chain_err(|| format!("Please install '{}'!", program))?;
35+
execs::cmd(program).arg("-v")
36+
.output()
37+
.chain_err(|| format!("Please install '{}'!", program))?;
3938
Ok(())
4039
}
4140

4241
fn npm_package_exists(package: &str) -> Result<()> {
43-
let status = execs::cmd("npm")
44-
.args(&["list", "-g"])
45-
.arg(package)
46-
.output();
42+
let status = execs::cmd("npm").args(&["list", "-g"])
43+
.arg(package)
44+
.output();
4745

4846
match status {
4947
Ok(ref out) if out.status.success() => Ok(()),
5048
_ => {
51-
bail!("Missing npm package '{0}' \
52-
install with: 'npm -g install {0}'",
49+
bail!("Missing npm package '{0}' install with: 'npm -g install {0}'",
5350
package)
54-
},
51+
}
5552
}
5653
}
5754

5855
pub enum Resource<'a> {
5956
Program(&'a str),
6057
Package(&'a str),
6158
}
62-
use Resource::{Program, Package};
59+
use Resource::{Package, Program};
6360

6461
impl<'a> Resource<'a> {
6562
pub fn exists(&self) -> Result<()> {
@@ -71,7 +68,6 @@ impl<'a> Resource<'a> {
7168
}
7269

7370
fn run() -> Result<()> {
74-
7571
if let Ok(_) = env::var("CARGO_FEATURE_REGENERATE_CSS") {
7672
// Check dependencies
7773
Program("npm").exists()?;
@@ -85,14 +81,14 @@ fn run() -> Result<()> {
8581
let theme_dir = Path::new(&manifest_dir).join("src/theme/");
8682
let stylus_dir = theme_dir.join("stylus/book.styl");
8783

88-
if !execs::cmd("stylus")
89-
.arg(stylus_dir)
90-
.arg("--out")
91-
.arg(theme_dir)
92-
.arg("--use")
93-
.arg("nib")
94-
.status()?
95-
.success() {
84+
if !execs::cmd("stylus").arg(stylus_dir)
85+
.arg("--out")
86+
.arg(theme_dir)
87+
.arg("--use")
88+
.arg("nib")
89+
.status()?
90+
.success()
91+
{
9692
bail!("Stylus encoutered an error");
9793
}
9894
}

rustfmt.toml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
write_mode = "Overwrite"
1+
array_layout = "Visual"
2+
chain_indent = "Visual"
3+
fn_args_layout = "Visual"
4+
fn_call_style = "Visual"
5+
format_strings = true
6+
generics_indent = "Visual"
27

3-
max_width = 120
4-
ideal_width = 120
5-
fn_call_width = 100
6-
7-
fn_args_density = "Compressed"
8-
9-
enum_trailing_comma = true
10-
match_block_trailing_comma = true
11-
struct_trailing_comma = "Always"
12-
wrap_comments = true
13-
use_try_shorthand = true
14-
15-
report_todo = "Always"
16-
report_fixme = "Always"

src/bin/build.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{ArgMatches, SubCommand, App};
1+
use clap::{App, ArgMatches, SubCommand};
22
use mdbook::MDBook;
33
use mdbook::errors::Result;
44
use {get_book_dir, open};
@@ -8,10 +8,21 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
88
SubCommand::with_name("build")
99
.about("Build the book from the markdown files")
1010
.arg_from_usage("-o, --open 'Open the compiled book in a web browser'")
11-
.arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'")
12-
.arg_from_usage("--no-create 'Will not create non-existent files linked from SUMMARY.md'")
13-
.arg_from_usage("--curly-quotes 'Convert straight quotes to curly quotes, except for those that occur in code blocks and code spans'")
14-
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
11+
.arg_from_usage(
12+
"-d, --dest-dir=[dest-dir] 'The output directory for your \
13+
book{n}(Defaults to ./book when omitted)'",
14+
)
15+
.arg_from_usage(
16+
"--no-create 'Will not create non-existent files linked from SUMMARY.md'",
17+
)
18+
.arg_from_usage(
19+
"--curly-quotes 'Convert straight quotes to curly quotes, except for those \
20+
that occur in code blocks and code spans'",
21+
)
22+
.arg_from_usage(
23+
"[dir] 'A directory for your book{n}(Defaults to Current Directory \
24+
when omitted)'",
25+
)
1526
}
1627

1728
// Build command implementation

src/bin/init.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io;
22
use std::io::Write;
3-
use clap::{ArgMatches, SubCommand, App};
3+
use clap::{App, ArgMatches, SubCommand};
44
use mdbook::MDBook;
55
use mdbook::errors::Result;
66
use get_book_dir;
@@ -10,14 +10,14 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
1010
SubCommand::with_name("init")
1111
.about("Create boilerplate structure and files in the directory")
1212
// the {n} denotes a newline which will properly aligned in all help messages
13-
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
13+
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory \
14+
when omitted)'")
1415
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
1516
.arg_from_usage("--force 'skip confirmation prompts'")
1617
}
1718

1819
// Init command implementation
1920
pub fn execute(args: &ArgMatches) -> Result<()> {
20-
2121
let book_dir = get_book_dir(args);
2222
let mut book = MDBook::new(&book_dir);
2323

@@ -26,7 +26,6 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
2626

2727
// If flag `--theme` is present, copy theme to src
2828
if args.is_present("theme") {
29-
3029
// Skip this if `--force` is present
3130
if !args.is_present("force") {
3231
// Print warning
@@ -45,7 +44,6 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
4544
// Call the function that copies the theme
4645
book.copy_theme()?;
4746
println!("\nTheme copied.");
48-
4947
}
5048

5149
// Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`

src/bin/mdbook.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
extern crate mdbook;
21
#[macro_use]
32
extern crate clap;
4-
extern crate log;
53
extern crate env_logger;
4+
extern crate log;
5+
extern crate mdbook;
66
extern crate open;
77

88
use std::env;
99
use std::ffi::OsStr;
1010
use std::io::{self, Write};
1111
use std::path::{Path, PathBuf};
12-
use clap::{App, ArgMatches, AppSettings};
13-
use log::{LogRecord, LogLevelFilter};
12+
use clap::{App, AppSettings, ArgMatches};
13+
use log::{LogLevelFilter, LogRecord};
1414
use env_logger::LogBuilder;
1515

1616
pub mod build;
@@ -33,7 +33,10 @@ fn main() {
3333
// Get the version from our Cargo.toml using clap's crate_version!() macro
3434
.version(concat!("v",crate_version!()))
3535
.setting(AppSettings::SubcommandRequired)
36-
.after_help("For more information about a specific command, try `mdbook <command> --help`\nSource code for mdbook available at: https://github.com/azerupi/mdBook")
36+
.after_help("For more information about a specific command, \
37+
try `mdbook <command> --help`\n\
38+
Source code for mdbook available \
39+
at: https://github.com/azerupi/mdBook")
3740
.subcommand(init::make_subcommand())
3841
.subcommand(build::make_subcommand())
3942
.subcommand(test::make_subcommand());
@@ -71,7 +74,7 @@ fn init_logger() {
7174
builder.format(format).filter(None, LogLevelFilter::Info);
7275

7376
if let Ok(var) = env::var("RUST_LOG") {
74-
builder.parse(&var);
77+
builder.parse(&var);
7578
}
7679

7780
builder.init().unwrap();

src/bin/serve.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ extern crate ws;
44

55
use std;
66
use std::path::Path;
7-
use self::iron::{Iron, AfterMiddleware, IronResult, IronError, Request, Response, status, Set, Chain};
8-
use clap::{ArgMatches, SubCommand, App};
7+
use self::iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response,
8+
Set};
9+
use clap::{App, ArgMatches, SubCommand};
910
use mdbook::MDBook;
1011
use mdbook::errors::Result;
1112
use {get_book_dir, open};
@@ -17,14 +18,33 @@ struct ErrorRecover;
1718
// Create clap subcommand arguments
1819
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
1920
SubCommand::with_name("serve")
20-
.about("Serve the book at http://localhost:3000. Rebuild and reload on change.")
21-
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
22-
.arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'")
23-
.arg_from_usage("--curly-quotes 'Convert straight quotes to curly quotes, except for those that occur in code blocks and code spans'")
21+
.about(
22+
"Serve the book at http://localhost:3000. Rebuild and reload on change.",
23+
)
24+
.arg_from_usage(
25+
"[dir] 'A directory for your book{n}(Defaults to \
26+
Current Directory when omitted)'",
27+
)
28+
.arg_from_usage(
29+
"-d, --dest-dir=[dest-dir] 'The output directory for \
30+
your book{n}(Defaults to ./book when omitted)'",
31+
)
32+
.arg_from_usage(
33+
"--curly-quotes 'Convert straight quotes to curly quotes, except \
34+
for those that occur in code blocks and code spans'",
35+
)
2436
.arg_from_usage("-p, --port=[port] 'Use another port{n}(Defaults to 3000)'")
25-
.arg_from_usage("-w, --websocket-port=[ws-port] 'Use another port for the websocket connection (livereload){n}(Defaults to 3001)'")
26-
.arg_from_usage("-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'")
27-
.arg_from_usage("-a, --address=[address] 'Address that the browser can reach the websocket server from{n}(Defaults to the interface address)'")
37+
.arg_from_usage(
38+
"-w, --websocket-port=[ws-port] 'Use another port for the \
39+
websocket connection (livereload){n}(Defaults to 3001)'",
40+
)
41+
.arg_from_usage(
42+
"-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'",
43+
)
44+
.arg_from_usage(
45+
"-a, --address=[address] 'Address that the browser can reach the \
46+
websocket server from{n}(Defaults to the interface address)'",
47+
)
2848
.arg_from_usage("-o, --open 'Open the book server in a web browser'")
2949
}
3050

@@ -53,7 +73,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
5373
let address = format!("{}:{}", interface, port);
5474
let ws_address = format!("{}:{}", interface, ws_port);
5575

56-
book.set_livereload(format!(r#"
76+
book.set_livereload(format!(
77+
r#"
5778
<script type="text/javascript">
5879
var socket = new WebSocket("ws://{}:{}");
5980
socket.onmessage = function (event) {{
@@ -68,9 +89,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
6889
}}
6990
</script>
7091
"#,
71-
public_address,
72-
ws_port,
73-
RELOAD_COMMAND));
92+
public_address,
93+
ws_port,
94+
RELOAD_COMMAND
95+
));
7496

7597
book.build()?;
7698

src/bin/test.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{ArgMatches, SubCommand, App};
1+
use clap::{App, ArgMatches, SubCommand};
22
use mdbook::MDBook;
33
use mdbook::errors::Result;
44
use get_book_dir;
@@ -7,12 +7,16 @@ use get_book_dir;
77
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
88
SubCommand::with_name("test")
99
.about("Test that code samples compile")
10-
.arg_from_usage("-L, --library-path [DIR]... 'directory to add to crate search path'")
10+
.arg_from_usage(
11+
"-L, --library-path [DIR]... 'directory to add to crate search path'",
12+
)
1113
}
1214

1315
// test command implementation
1416
pub fn execute(args: &ArgMatches) -> Result<()> {
15-
let library_paths: Vec<&str> = args.values_of("library-path").map(|v| v.collect()).unwrap_or_default();
17+
let library_paths: Vec<&str> = args.values_of("library-path")
18+
.map(|v| v.collect())
19+
.unwrap_or_default();
1620
let book_dir = get_book_dir(args);
1721
let mut book = MDBook::new(&book_dir).read_config()?;
1822

0 commit comments

Comments
 (0)