Skip to content

Commit

Permalink
More refactor (#225)
Browse files Browse the repository at this point in the history
- Major changes in `lychee-lib::filter` module:
  - Fields in `Excludes` except the `RegexSet` is now moved to `Filter`.
  - `Filter` contains `Option<Excludes>` and `Option<Includes>`, which are
    wrapper struct of `RegexSet` instead of `Option<RegexSet>`. As a result
    the code now looks cleaner.
  - Factored out some filtering logics to dedicated functions.
    - It's possible to write tests for those functions in addition to tests
      for the `Filter` struct.
  - Added docs to `Filter::is_excluded` and reorgnized the code.
- placed `derive_builder` by `typed_builder`:
  - The internal interface very ugly, as admitted by the author, but we no
    longer have nested `Option`s like before.
  - As a result, the `Client` building is much easier to read.
  - Main benefit of `typed_builder` is, the arguments feeded to builder is
    checked at compile time instead of run-time.
- Fixed a bug in `lychee::tests::usage` and `lychee-lib::stats::test`.
  - Now it will clear environment variable which would otherwise cause an
    issue if `GITHUB_TOKEN` is set.
- Updated dependencies.

Co-authored-by: Lucius Hu <[email protected]>
  • Loading branch information
lebensterben and lebensterben authored Apr 16, 2021
1 parent 63774c9 commit f64213d
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 304 deletions.
94 changes: 13 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ USAGE:
lychee [FLAGS] [OPTIONS] [--] [inputs]...
FLAGS:
-E, --exclude-all-private Exclude all private IPs from checking. Equivalent to `--exclude-private --exclude-link-
local --exclude-loopback`
-E, --exclude-all-private Exclude all private IPs from checking.
Equivalent to `--exclude-private --exclude-link-local --exclude-loopback`
--exclude-link-local Exclude link-local IP address range from checking
--exclude-loopback Exclude loopback IP address range from checking
--exclude-mail Exclude all mail addresses from checking
--exclude-private Exclude private IP address ranges from checking
--glob-ignore-case Ignore case when expanding filesystem path glob inputs
--help Prints help information
-i, --insecure Proceed for server connections considered insecure (invalid TLS)
-n, --no-progress Do not show progress bar. This is recommended for non-interactive shells (e.g. for
continuous integration)
-n, --no-progress Do not show progress bar.
This is recommended for non-interactive shells (e.g. for continuous integration)
--skip-missing Skip missing input files (default is to error if they don't exist)
-V, --version Prints version information
-v, --verbose Verbose program output
Expand Down Expand Up @@ -226,7 +226,7 @@ use lychee_lib::{ClientBuilder, Result, Status};

#[tokio::main]
async fn main() -> Result<()> {
let client = ClientBuilder::default().build()?;
let client = ClientBuilder::default().client()?;
let response = client.check("https://github.com/lycheeverse/lychee").await?;
assert!(response.status().is_success());
Ok(())
Expand All @@ -236,7 +236,7 @@ async fn main() -> Result<()> {
The client builder is very customizable:

```rust, ignore
let client = lychee_lib::ClientBuilder::default()
let client = lychee_lib::ClientBuilder::builder()
.includes(includes)
.excludes(excludes)
.max_redirects(cfg.max_redirects)
Expand All @@ -249,7 +249,8 @@ let client = lychee_lib::ClientBuilder::default()
.github_token(cfg.github_token)
.scheme(cfg.scheme)
.accepted(accepted)
.build()?;
.build()
.client()?;
```

All options that you set will be used for all link checks.
Expand Down
3 changes: 2 additions & 1 deletion lychee-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn run(cfg: &Config, inputs: Vec<Input>) -> Result<i32> {
let include = RegexSet::new(&cfg.include)?;
let exclude = RegexSet::new(&cfg.exclude)?;

let client = ClientBuilder::default()
let client = ClientBuilder::builder()
.includes(include)
.excludes(exclude)
.exclude_all_private(cfg.exclude_all_private)
Expand All @@ -138,6 +138,7 @@ async fn run(cfg: &Config, inputs: Vec<Input>) -> Result<i32> {
.scheme(cfg.scheme.clone())
.accepted(accepted)
.build()
.client()
.map_err(|e| anyhow!(e))?;

let links = collect_links(
Expand Down
7 changes: 3 additions & 4 deletions lychee-bin/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ pub(crate) struct Config {
pub(crate) verbose: bool,

/// Do not show progress bar.
/// This is recommended for non-interactive shells (e.g. for continuous
/// integration)
#[structopt(short, long)]
/// This is recommended for non-interactive shells (e.g. for continuous integration)
#[structopt(short, long, verbatim_doc_comment)]
#[serde(default)]
pub(crate) no_progress: bool,

Expand Down Expand Up @@ -167,7 +166,7 @@ pub(crate) struct Config {

/// Exclude all private IPs from checking.
/// Equivalent to `--exclude-private --exclude-link-local --exclude-loopback`
#[structopt(short = "E", long)]
#[structopt(short = "E", long, verbatim_doc_comment)]
#[serde(default)]
pub(crate) exclude_all_private: bool,

Expand Down
2 changes: 1 addition & 1 deletion lychee-bin/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod test {
.await;

ClientBuilder::default()
.build()
.client()
.unwrap()
.check(mock_server.uri())
.await
Expand Down
2 changes: 1 addition & 1 deletion lychee-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ version = "0.6.0"
[dependencies]
check-if-email-exists = "0.8.21"
deadpool = "0.7.0"
derive_builder = "0.10.0"
fast_chemail = "0.9.6"
glob = "0.3.0"
html5ever = "0.25.1"
Expand All @@ -39,6 +38,7 @@ ring = "0.16.20"
serde = { version = "1.0.125", features = ["derive"] }
shellexpand = "2.1.0"
tokio = { version = "1.5.0", features = ["full"] }
typed-builder = "0.9.0"
url = { version = "2.2.1", features = ["serde"] }

[dev-dependencies]
Expand Down
Loading

0 comments on commit f64213d

Please sign in to comment.