-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split cargo-deadlinks and deadlinks into two binaries
- Expose public `walk_dir` function, which prints all missing files - `impl Clone for CheckContext` - Put cargo dependencies behind a feature gate - Switch from `Into` to `From` to help type inference
- Loading branch information
Showing
5 changed files
with
137 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::path::PathBuf; | ||
use std::process; | ||
|
||
use cargo_deadlinks::{walk_dir, CheckContext}; | ||
use docopt::Docopt; | ||
use serde_derive::Deserialize; | ||
|
||
mod shared; | ||
|
||
const MAIN_USAGE: &str = " | ||
Check your package's documentation for dead links. | ||
Usage: | ||
deadlinks <directory> [options] | ||
Options: | ||
-h --help Print this message | ||
--check-http Check 'http' and 'https' scheme links | ||
--debug Use debug output | ||
-v --verbose Use verbose output | ||
-V --version Print version info and exit. | ||
"; | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct MainArgs { | ||
arg_directory: PathBuf, | ||
flag_verbose: bool, | ||
flag_debug: bool, | ||
flag_check_http: bool, | ||
} | ||
|
||
impl From<MainArgs> for CheckContext { | ||
fn from(args: MainArgs) -> CheckContext { | ||
CheckContext { | ||
check_http: args.flag_check_http, | ||
verbose: args.flag_debug, | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let args: MainArgs = Docopt::new(MAIN_USAGE) | ||
.and_then(|d| { | ||
d.version(Some(env!("CARGO_PKG_VERSION").to_owned())) | ||
.deserialize() | ||
}) | ||
.unwrap_or_else(|e| e.exit()); | ||
shared::init_logger(args.flag_debug, args.flag_verbose, "deadlinks"); | ||
|
||
let dir = match args.arg_directory.canonicalize() { | ||
Ok(dir) => dir, | ||
Err(_) => { | ||
println!("Could not find directory {:?}.", args.arg_directory); | ||
process::exit(1); | ||
} | ||
}; | ||
log::info!("checking directory {:?}", dir); | ||
if walk_dir(&dir, args.into()) { | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use log::LevelFilter; | ||
|
||
/// Initalizes the logger according to the provided config flags. | ||
pub fn init_logger(debug: bool, verbose: bool, krate: &str) { | ||
use std::io::Write; | ||
|
||
let mut builder = env_logger::Builder::new(); | ||
builder.format(|f, record| writeln!(f, "{}", record.args())); | ||
match (debug, verbose) { | ||
(true, _) => { | ||
builder.filter(Some(krate), LevelFilter::Debug); | ||
} | ||
(false, true) => { | ||
builder.filter(Some(krate), LevelFilter::Info); | ||
} | ||
(false, false) => { | ||
builder.filter(Some(krate), LevelFilter::Error); | ||
} | ||
} | ||
builder.init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters