Skip to content

run rustfmt on the repository #398(Updated) #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c02ec1e
remove rustfmt.toml
prertik Sep 15, 2017
23e432d
rustfmt the repository #398
prertik Sep 15, 2017
ef25ce8
rustfmt the repository #398
prertik Sep 15, 2017
395159e
rustfmt the repository #398
prertik Sep 15, 2017
c78ffed
rustfmt the repository #398
prertik Sep 15, 2017
673ba7b
rustfmt the repository #398
prertik Sep 15, 2017
8828829
rustfmt the repository #398
prertik Sep 15, 2017
bb12d6b
rustfmt the repository #398
prertik Sep 15, 2017
0b14b31
rustfmt the repository #398
prertik Sep 15, 2017
11d300b
rustfmt the repository #398
prertik Sep 15, 2017
434250a
rustfmt the repository #398
prertik Sep 15, 2017
12aca69
rustfmt the repository #398
prertik Sep 15, 2017
b86e67e
rustfmt the repository #398
prertik Sep 15, 2017
85d68cd
rustfmt the repository #398
prertik Sep 15, 2017
657b56e
rustfmt the repository #398
prertik Sep 15, 2017
049ba72
rustfmt the repository #398
prertik Sep 15, 2017
658994f
rustfmt the repository #398
prertik Sep 15, 2017
0982545
rustfmt the repository #398
prertik Sep 15, 2017
67359ae
rustfmt the repository #398
prertik Sep 15, 2017
affc527
rustfmt the repository #398
prertik Sep 15, 2017
cee4570
rustfmt the repository #398
prertik Sep 15, 2017
4d41e80
rustfmt the repository #398
prertik Sep 15, 2017
89295d6
rustfmt the repository #398
prertik Sep 15, 2017
28bf0ba
rustfmt the repository #398
prertik Sep 15, 2017
0c929e1
rustfmt the repository #398
prertik Sep 15, 2017
0269252
rustfmt the repository #398
prertik Sep 15, 2017
cca9b0b
rustfmt the repository #398
prertik Sep 15, 2017
4380240
rustfmt the repository #398
prertik Sep 15, 2017
025f1d3
rustfmt the repository #398
prertik Sep 15, 2017
f1f2e5c
rustfmt the repository #398
prertik Sep 15, 2017
7a15dc9
rustfmt the repository #398
prertik Sep 15, 2017
69852e4
rustfmt the repository #398
prertik Sep 15, 2017
83d598e
rustfmt the repository #398
prertik Sep 15, 2017
2953e96
rustfmt the repository #398
prertik Sep 15, 2017
0cd8c3a
rustfmt the repository #398
prertik Sep 15, 2017
737fe11
rustfmt the repository #398
prertik Sep 15, 2017
c20bd89
rustfmt the repository #398
prertik Sep 15, 2017
f392a93
rustfmt the repository #398
prertik Sep 15, 2017
f785491
rustfmt the repository #398
prertik Sep 15, 2017
5cbede9
fix formatting for html
prertik Sep 15, 2017
a9819c5
fix for test passing scenario
prertik Sep 15, 2017
fd3b34a
better formatted code
prertik Sep 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,31 @@ error_chain!{
}

fn program_exists(program: &str) -> Result<()> {
execs::cmd(program)
.arg("-v")
.output()
.chain_err(|| format!("Please install '{}'!", program))?;
execs::cmd(program).arg("-v")
.output()
.chain_err(|| format!("Please install '{}'!", program))?;
Ok(())
}

fn npm_package_exists(package: &str) -> Result<()> {
let status = execs::cmd("npm")
.args(&["list", "-g"])
.arg(package)
.output();
let status = execs::cmd("npm").args(&["list", "-g"])
.arg(package)
.output();

match status {
Ok(ref out) if out.status.success() => Ok(()),
_ => {
bail!("Missing npm package '{0}' \
install with: 'npm -g install {0}'",
bail!("Missing npm package '{0}' install with: 'npm -g install {0}'",
package)
},
}
}
}

pub enum Resource<'a> {
Program(&'a str),
Package(&'a str),
}
use Resource::{Program, Package};
use Resource::{Package, Program};

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

fn run() -> Result<()> {

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

if !execs::cmd("stylus")
.arg(stylus_dir)
.arg("--out")
.arg(theme_dir)
.arg("--use")
.arg("nib")
.status()?
.success() {
if !execs::cmd("stylus").arg(stylus_dir)
.arg("--out")
.arg(theme_dir)
.arg("--use")
.arg("nib")
.status()?
.success()
{
bail!("Stylus encoutered an error");
}
}
Expand Down
21 changes: 6 additions & 15 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
write_mode = "Overwrite"
array_layout = "Visual"
chain_indent = "Visual"
fn_args_layout = "Visual"
fn_call_style = "Visual"
format_strings = true
generics_indent = "Visual"

max_width = 120
ideal_width = 120
fn_call_width = 100

fn_args_density = "Compressed"

enum_trailing_comma = true
match_block_trailing_comma = true
struct_trailing_comma = "Always"
wrap_comments = true
use_try_shorthand = true

report_todo = "Always"
report_fixme = "Always"
21 changes: 16 additions & 5 deletions src/bin/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{ArgMatches, SubCommand, App};
use clap::{App, ArgMatches, SubCommand};
use mdbook::MDBook;
use mdbook::errors::Result;
use {get_book_dir, open};
Expand All @@ -8,10 +8,21 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("build")
.about("Build the book from the markdown files")
.arg_from_usage("-o, --open 'Open the compiled book in a web browser'")
.arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'")
.arg_from_usage("--no-create 'Will not create non-existent files linked from SUMMARY.md'")
.arg_from_usage("--curly-quotes 'Convert straight quotes to curly quotes, except for those that occur in code blocks and code spans'")
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
.arg_from_usage(
"-d, --dest-dir=[dest-dir] 'The output directory for your \
book{n}(Defaults to ./book when omitted)'",
)
.arg_from_usage(
"--no-create 'Will not create non-existent files linked from SUMMARY.md'",
)
.arg_from_usage(
"--curly-quotes 'Convert straight quotes to curly quotes, except for those \
that occur in code blocks and code spans'",
)
.arg_from_usage(
"[dir] 'A directory for your book{n}(Defaults to Current Directory \
when omitted)'",
)
}

// Build command implementation
Expand Down
8 changes: 3 additions & 5 deletions src/bin/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::io::Write;
use clap::{ArgMatches, SubCommand, App};
use clap::{App, ArgMatches, SubCommand};
use mdbook::MDBook;
use mdbook::errors::Result;
use get_book_dir;
Expand All @@ -10,14 +10,14 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("init")
.about("Create boilerplate structure and files in the directory")
// the {n} denotes a newline which will properly aligned in all help messages
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory \
when omitted)'")
.arg_from_usage("--theme 'Copies the default theme into your source folder'")
.arg_from_usage("--force 'skip confirmation prompts'")
}

// Init command implementation
pub fn execute(args: &ArgMatches) -> Result<()> {

let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir);

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

// If flag `--theme` is present, copy theme to src
if args.is_present("theme") {

// Skip this if `--force` is present
if !args.is_present("force") {
// Print warning
Expand All @@ -45,7 +44,6 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
// Call the function that copies the theme
book.copy_theme()?;
println!("\nTheme copied.");

}

// Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`
Expand Down
15 changes: 9 additions & 6 deletions src/bin/mdbook.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
extern crate mdbook;
#[macro_use]
extern crate clap;
extern crate log;
extern crate env_logger;
extern crate log;
extern crate mdbook;
extern crate open;

use std::env;
use std::ffi::OsStr;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use clap::{App, ArgMatches, AppSettings};
use log::{LogRecord, LogLevelFilter};
use clap::{App, AppSettings, ArgMatches};
use log::{LogLevelFilter, LogRecord};
use env_logger::LogBuilder;

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

if let Ok(var) = env::var("RUST_LOG") {
builder.parse(&var);
builder.parse(&var);
}

builder.init().unwrap();
Expand Down
48 changes: 35 additions & 13 deletions src/bin/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ extern crate ws;

use std;
use std::path::Path;
use self::iron::{Iron, AfterMiddleware, IronResult, IronError, Request, Response, status, Set, Chain};
use clap::{ArgMatches, SubCommand, App};
use self::iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response,
Set};
use clap::{App, ArgMatches, SubCommand};
use mdbook::MDBook;
use mdbook::errors::Result;
use {get_book_dir, open};
Expand All @@ -17,14 +18,33 @@ struct ErrorRecover;
// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("serve")
.about("Serve the book at http://localhost:3000. Rebuild and reload on change.")
.arg_from_usage("[dir] 'A directory for your book{n}(Defaults to Current Directory when omitted)'")
.arg_from_usage("-d, --dest-dir=[dest-dir] 'The output directory for your book{n}(Defaults to ./book when omitted)'")
.arg_from_usage("--curly-quotes 'Convert straight quotes to curly quotes, except for those that occur in code blocks and code spans'")
.about(
"Serve the book at http://localhost:3000. Rebuild and reload on change.",
)
.arg_from_usage(
"[dir] 'A directory for your book{n}(Defaults to \
Current Directory when omitted)'",
)
.arg_from_usage(
"-d, --dest-dir=[dest-dir] 'The output directory for \
your book{n}(Defaults to ./book when omitted)'",
)
.arg_from_usage(
"--curly-quotes 'Convert straight quotes to curly quotes, except \
for those that occur in code blocks and code spans'",
)
.arg_from_usage("-p, --port=[port] 'Use another port{n}(Defaults to 3000)'")
.arg_from_usage("-w, --websocket-port=[ws-port] 'Use another port for the websocket connection (livereload){n}(Defaults to 3001)'")
.arg_from_usage("-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'")
.arg_from_usage("-a, --address=[address] 'Address that the browser can reach the websocket server from{n}(Defaults to the interface address)'")
.arg_from_usage(
"-w, --websocket-port=[ws-port] 'Use another port for the \
websocket connection (livereload){n}(Defaults to 3001)'",
)
.arg_from_usage(
"-i, --interface=[interface] 'Interface to listen on{n}(Defaults to localhost)'",
)
.arg_from_usage(
"-a, --address=[address] 'Address that the browser can reach the \
websocket server from{n}(Defaults to the interface address)'",
)
.arg_from_usage("-o, --open 'Open the book server in a web browser'")
}

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

book.set_livereload(format!(r#"
book.set_livereload(format!(
r#"
<script type="text/javascript">
var socket = new WebSocket("ws://{}:{}");
socket.onmessage = function (event) {{
Expand All @@ -68,9 +89,10 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
}}
</script>
"#,
public_address,
ws_port,
RELOAD_COMMAND));
public_address,
ws_port,
RELOAD_COMMAND
));

book.build()?;

Expand Down
10 changes: 7 additions & 3 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{ArgMatches, SubCommand, App};
use clap::{App, ArgMatches, SubCommand};
use mdbook::MDBook;
use mdbook::errors::Result;
use get_book_dir;
Expand All @@ -7,12 +7,16 @@ use get_book_dir;
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("test")
.about("Test that code samples compile")
.arg_from_usage("-L, --library-path [DIR]... 'directory to add to crate search path'")
.arg_from_usage(
"-L, --library-path [DIR]... 'directory to add to crate search path'",
)
}

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

Expand Down
Loading