2022-02-07 21:45:17 +00:00
|
|
|
use std::{convert::TryFrom, fs, io::ErrorKind, path::PathBuf, str::FromStr, time::Duration};
|
2020-12-02 22:28:37 +00:00
|
|
|
|
2022-03-27 00:27:27 +00:00
|
|
|
use anyhow::{anyhow, Context, Error, Result};
|
2022-02-07 21:45:17 +00:00
|
|
|
use const_format::{concatcp, formatcp};
|
2022-01-07 00:03:10 +00:00
|
|
|
use lychee_lib::{
|
2022-02-24 11:24:57 +00:00
|
|
|
Base, Input, DEFAULT_MAX_REDIRECTS, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_WAIT_TIME_SECS,
|
|
|
|
|
DEFAULT_TIMEOUT_SECS, DEFAULT_USER_AGENT,
|
2022-01-07 00:03:10 +00:00
|
|
|
};
|
2022-02-13 12:53:46 +00:00
|
|
|
use secrecy::{ExposeSecret, SecretString};
|
2020-10-21 00:10:25 +00:00
|
|
|
use serde::Deserialize;
|
2022-01-07 00:03:10 +00:00
|
|
|
use structopt::StructOpt;
|
2020-10-21 00:10:25 +00:00
|
|
|
|
2022-01-14 14:25:51 +00:00
|
|
|
pub(crate) const LYCHEE_IGNORE_FILE: &str = ".lycheeignore";
|
|
|
|
|
pub(crate) const LYCHEE_CACHE_FILE: &str = ".lycheecache";
|
|
|
|
|
|
2022-02-07 22:17:50 +00:00
|
|
|
const DEFAULT_METHOD: &str = "get";
|
|
|
|
|
const DEFAULT_MAX_CACHE_AGE: &str = "1d";
|
|
|
|
|
const DEFAULT_MAX_CONCURRENCY: usize = 128;
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
|
|
|
|
|
// this exists because structopt requires `&str` type values for defaults
|
2022-02-07 22:17:50 +00:00
|
|
|
// whereas serde expects owned `String` types
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
// (we can't use e.g. `TIMEOUT` or `timeout()` which gets created for serde)
|
2022-02-07 22:17:50 +00:00
|
|
|
const MAX_CONCURRENCY_STR: &str = concatcp!(DEFAULT_MAX_CONCURRENCY);
|
|
|
|
|
const MAX_CACHE_AGE_STR: &str = concatcp!(DEFAULT_MAX_CACHE_AGE);
|
2022-02-07 21:45:17 +00:00
|
|
|
const MAX_REDIRECTS_STR: &str = concatcp!(DEFAULT_MAX_REDIRECTS);
|
|
|
|
|
const MAX_RETRIES_STR: &str = concatcp!(DEFAULT_MAX_RETRIES);
|
|
|
|
|
const STRUCTOPT_HELP_MSG_CACHE: &str = formatcp!(
|
|
|
|
|
"Use request cache stored on disk at `{}`",
|
|
|
|
|
LYCHEE_CACHE_FILE,
|
|
|
|
|
);
|
|
|
|
|
const STRUCTOPT_HELP_MSG_IGNORE_FILE: &str = formatcp!(
|
|
|
|
|
"File or files that contain URLs to be excluded from checking. Regular
|
2022-01-14 14:25:51 +00:00
|
|
|
expressions supported; one pattern per line. Automatically excludes
|
|
|
|
|
patterns from `{}` if file exists",
|
2022-02-07 21:45:17 +00:00
|
|
|
LYCHEE_IGNORE_FILE,
|
|
|
|
|
);
|
2022-02-24 11:24:57 +00:00
|
|
|
const TIMEOUT_STR: &str = concatcp!(DEFAULT_TIMEOUT_SECS);
|
|
|
|
|
const RETRY_WAIT_TIME_STR: &str = concatcp!(DEFAULT_RETRY_WAIT_TIME_SECS);
|
2020-12-02 22:28:37 +00:00
|
|
|
|
2022-04-25 17:19:36 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) enum Format {
|
2021-11-17 23:44:48 +00:00
|
|
|
Compact,
|
|
|
|
|
Detailed,
|
2021-02-18 00:32:48 +00:00
|
|
|
Json,
|
2021-11-17 23:44:48 +00:00
|
|
|
Markdown,
|
2022-04-25 17:19:36 +00:00
|
|
|
Raw,
|
2020-12-14 00:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromStr for Format {
|
|
|
|
|
type Err = Error;
|
|
|
|
|
fn from_str(format: &str) -> Result<Self, Self::Err> {
|
2022-04-25 17:19:36 +00:00
|
|
|
match format.to_lowercase().as_str() {
|
2021-11-17 23:44:48 +00:00
|
|
|
"compact" | "string" => Ok(Format::Compact),
|
|
|
|
|
"detailed" => Ok(Format::Detailed),
|
2021-02-18 00:32:48 +00:00
|
|
|
"json" => Ok(Format::Json),
|
2021-11-17 23:44:48 +00:00
|
|
|
"markdown" | "md" => Ok(Format::Markdown),
|
2022-04-25 17:19:36 +00:00
|
|
|
"raw" => Ok(Format::Raw),
|
|
|
|
|
_ => Err(anyhow!("Unknown format {}", format)),
|
2020-12-14 00:15:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Format {
|
|
|
|
|
fn default() -> Self {
|
2021-11-17 23:44:48 +00:00
|
|
|
Format::Compact
|
2020-12-14 00:15:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
// Macro for generating default functions to be used by serde
|
|
|
|
|
macro_rules! default_function {
|
|
|
|
|
( $( $name:ident : $T:ty = $e:expr; )* ) => {
|
|
|
|
|
$(
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
#[allow(clippy::missing_const_for_fn)]
|
2020-10-21 00:10:25 +00:00
|
|
|
fn $name() -> $T {
|
|
|
|
|
$e
|
|
|
|
|
}
|
|
|
|
|
)*
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
// Generate the functions for serde defaults
|
|
|
|
|
default_function! {
|
2022-01-07 00:03:10 +00:00
|
|
|
max_redirects: usize = DEFAULT_MAX_REDIRECTS;
|
|
|
|
|
max_retries: u64 = DEFAULT_MAX_RETRIES;
|
2022-02-07 22:17:50 +00:00
|
|
|
max_concurrency: usize = DEFAULT_MAX_CONCURRENCY;
|
|
|
|
|
max_cache_age: Duration = humantime::parse_duration(DEFAULT_MAX_CACHE_AGE).unwrap();
|
2022-01-07 00:03:10 +00:00
|
|
|
user_agent: String = DEFAULT_USER_AGENT.to_string();
|
2022-02-24 11:24:57 +00:00
|
|
|
timeout: usize = DEFAULT_TIMEOUT_SECS;
|
|
|
|
|
retry_wait_time: usize = DEFAULT_RETRY_WAIT_TIME_SECS;
|
2022-02-07 22:17:50 +00:00
|
|
|
method: String = DEFAULT_METHOD.to_string();
|
2020-12-02 22:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
// Macro for merging configuration values
|
|
|
|
|
macro_rules! fold_in {
|
|
|
|
|
( $cli:ident , $toml:ident ; $( $key:ident : $default:expr; )* ) => {
|
|
|
|
|
$(
|
|
|
|
|
if $cli.$key == $default && $toml.$key != $default {
|
|
|
|
|
$cli.$key = $toml.$key;
|
|
|
|
|
}
|
|
|
|
|
)*
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2021-06-22 22:18:12 +00:00
|
|
|
fn parse_base(src: &str) -> Result<Base, lychee_lib::ErrorKind> {
|
|
|
|
|
Base::try_from(src)
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
#[derive(Debug, StructOpt)]
|
2020-12-02 22:28:37 +00:00
|
|
|
#[structopt(
|
|
|
|
|
name = "lychee",
|
|
|
|
|
about = "A glorious link checker.\n\nProject home page: https://github.com/lycheeverse/lychee"
|
|
|
|
|
)]
|
2020-08-14 09:43:45 +00:00
|
|
|
pub(crate) struct LycheeOptions {
|
2020-12-02 22:28:37 +00:00
|
|
|
/// The inputs (where to get links to check from).
|
|
|
|
|
/// These can be: files (e.g. `README.md`), file globs (e.g. `"~/git/*/README.md"`),
|
2022-02-18 09:29:49 +00:00
|
|
|
/// remote URLs (e.g. `https://example.com/README.md`) or standard input (`-`).
|
2021-09-16 14:40:38 +00:00
|
|
|
/// NOTE: Use `--` to separate inputs from options that allow multiple arguments.
|
|
|
|
|
#[structopt(name = "inputs", required = true)]
|
2020-12-02 22:28:37 +00:00
|
|
|
raw_inputs: Vec<String>,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Configuration file to use
|
|
|
|
|
#[structopt(short, long = "config", default_value = "./lychee.toml")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) config_file: String,
|
2020-10-21 00:10:25 +00:00
|
|
|
|
|
|
|
|
#[structopt(flatten)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) config: Config,
|
2020-10-21 00:10:25 +00:00
|
|
|
}
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
impl LycheeOptions {
|
|
|
|
|
// This depends on config, which is why a method is required (we could
|
|
|
|
|
// accept a `Vec<Input>` in `LycheeOptions` and do the conversion there,
|
|
|
|
|
// but we'd get no access to `glob_ignore_case`.
|
|
|
|
|
/// Get parsed inputs from options.
|
2022-03-27 00:27:27 +00:00
|
|
|
pub(crate) fn inputs(&self) -> Result<Vec<Input>> {
|
2020-12-02 22:28:37 +00:00
|
|
|
self.raw_inputs
|
|
|
|
|
.iter()
|
2021-12-16 17:45:52 +00:00
|
|
|
.map(|s| Input::new(s, None, self.config.glob_ignore_case))
|
2022-03-27 00:27:27 +00:00
|
|
|
.collect::<Result<_, _>>()
|
|
|
|
|
.context("Cannot parse inputs from arguments")
|
2020-12-02 22:28:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
#[allow(clippy::struct_excessive_bools)]
|
2022-04-25 17:19:36 +00:00
|
|
|
#[derive(Debug, Deserialize, StructOpt, Clone)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) struct Config {
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Verbose program output
|
|
|
|
|
#[structopt(short, long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) verbose: bool,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2021-02-21 16:19:32 +00:00
|
|
|
/// Do not show progress bar.
|
2021-04-16 18:25:22 +00:00
|
|
|
/// This is recommended for non-interactive shells (e.g. for continuous integration)
|
|
|
|
|
#[structopt(short, long, verbatim_doc_comment)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) no_progress: bool,
|
2020-10-10 04:31:28 +00:00
|
|
|
|
2022-01-14 14:25:51 +00:00
|
|
|
#[structopt(help = &STRUCTOPT_HELP_MSG_CACHE)]
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) cache: bool,
|
|
|
|
|
|
2022-01-14 15:55:56 +00:00
|
|
|
/// Discard all cached requests older than this duration
|
2022-01-14 14:25:51 +00:00
|
|
|
#[structopt(
|
|
|
|
|
long,
|
|
|
|
|
parse(try_from_str = humantime::parse_duration),
|
2022-02-07 22:17:50 +00:00
|
|
|
default_value = &MAX_CACHE_AGE_STR
|
2022-01-14 14:25:51 +00:00
|
|
|
)]
|
2022-02-07 22:17:50 +00:00
|
|
|
#[serde(default = "max_cache_age")]
|
2022-01-14 14:25:51 +00:00
|
|
|
pub(crate) max_cache_age: Duration,
|
|
|
|
|
|
2021-09-06 14:10:48 +00:00
|
|
|
/// Don't perform any link checking.
|
|
|
|
|
/// Instead, dump all the links extracted from inputs that would be checked
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) dump: bool,
|
|
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Maximum number of allowed redirects
|
2020-12-02 22:28:37 +00:00
|
|
|
#[structopt(short, long, default_value = &MAX_REDIRECTS_STR)]
|
|
|
|
|
#[serde(default = "max_redirects")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) max_redirects: usize,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2022-01-07 00:03:10 +00:00
|
|
|
/// Maximum number of retries per request
|
|
|
|
|
#[structopt(long, default_value = &MAX_RETRIES_STR)]
|
|
|
|
|
#[serde(default = "max_retries")]
|
|
|
|
|
pub(crate) max_retries: u64,
|
|
|
|
|
|
2020-11-24 20:30:06 +00:00
|
|
|
/// Maximum number of concurrent network requests
|
2020-12-02 22:28:37 +00:00
|
|
|
#[structopt(long, default_value = &MAX_CONCURRENCY_STR)]
|
|
|
|
|
#[serde(default = "max_concurrency")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) max_concurrency: usize,
|
2020-11-24 20:30:06 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Number of threads to utilize.
|
|
|
|
|
/// Defaults to number of cores available to the system
|
|
|
|
|
#[structopt(short = "T", long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) threads: Option<usize>,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// User agent
|
2022-01-07 00:03:10 +00:00
|
|
|
#[structopt(short, long, default_value = DEFAULT_USER_AGENT)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default = "user_agent")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) user_agent: String,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Proceed for server connections considered insecure (invalid TLS)
|
|
|
|
|
#[structopt(short, long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) insecure: bool,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2021-04-26 16:24:54 +00:00
|
|
|
/// Only test links with the given schemes (e.g. http and https)
|
2020-10-21 00:10:25 +00:00
|
|
|
#[structopt(short, long)]
|
|
|
|
|
#[serde(default)]
|
2021-04-26 16:24:54 +00:00
|
|
|
pub(crate) scheme: Vec<String>,
|
2020-08-14 09:43:45 +00:00
|
|
|
|
2021-09-03 00:09:30 +00:00
|
|
|
/// Only check local files and block network requests.
|
2021-09-02 21:10:46 +00:00
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) offline: bool,
|
|
|
|
|
|
2020-10-25 12:41:06 +00:00
|
|
|
/// URLs to check (supports regex). Has preference over all excludes.
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) include: Vec<String>,
|
2020-10-25 12:41:06 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Exclude URLs from checking (supports regex)
|
2020-10-25 12:41:06 +00:00
|
|
|
#[structopt(long)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude: Vec<String>,
|
2020-08-14 13:24:41 +00:00
|
|
|
|
2022-01-14 14:25:51 +00:00
|
|
|
#[structopt(help = &STRUCTOPT_HELP_MSG_IGNORE_FILE)]
|
2021-09-01 15:37:31 +00:00
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) exclude_file: Vec<String>,
|
2021-09-03 00:12:03 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Exclude all private IPs from checking.
|
|
|
|
|
/// Equivalent to `--exclude-private --exclude-link-local --exclude-loopback`
|
2021-04-16 18:25:22 +00:00
|
|
|
#[structopt(short = "E", long, verbatim_doc_comment)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude_all_private: bool,
|
2020-10-17 08:01:06 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Exclude private IP address ranges from checking
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude_private: bool,
|
2020-10-09 14:29:20 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Exclude link-local IP address range from checking
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude_link_local: bool,
|
2020-10-09 14:29:20 +00:00
|
|
|
|
2021-10-06 09:33:23 +00:00
|
|
|
/// Exclude loopback IP address range and localhost from checking
|
2020-10-21 00:10:25 +00:00
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude_loopback: bool,
|
2020-10-09 14:29:20 +00:00
|
|
|
|
2021-02-10 10:58:04 +00:00
|
|
|
/// Exclude all mail addresses from checking
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) exclude_mail: bool,
|
2021-02-10 10:58:04 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Custom request headers
|
|
|
|
|
#[structopt(short, long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) headers: Vec<String>,
|
2020-08-14 15:36:43 +00:00
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Comma-separated list of accepted status codes for valid links
|
|
|
|
|
#[structopt(short, long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) accept: Option<String>,
|
2020-08-17 23:17:26 +00:00
|
|
|
|
2022-02-24 11:24:57 +00:00
|
|
|
/// Website timeout in seconds from connect to response finished
|
2020-12-02 22:28:37 +00:00
|
|
|
#[structopt(short, long, default_value = &TIMEOUT_STR)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default = "timeout")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) timeout: usize,
|
2020-08-21 22:36:03 +00:00
|
|
|
|
2022-02-24 11:24:57 +00:00
|
|
|
/// Minimum wait time in seconds between retries of failed requests
|
|
|
|
|
#[structopt(short, long, default_value = &RETRY_WAIT_TIME_STR)]
|
|
|
|
|
#[serde(default = "retry_wait_time")]
|
|
|
|
|
pub(crate) retry_wait_time: usize,
|
|
|
|
|
|
2020-10-21 00:10:25 +00:00
|
|
|
/// Request method
|
2020-11-24 20:30:06 +00:00
|
|
|
// Using `-X` as a short param similar to curl
|
2022-02-07 22:17:50 +00:00
|
|
|
#[structopt(short = "X", long, default_value = DEFAULT_METHOD)]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default = "method")]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) method: String,
|
2020-10-20 23:31:06 +00:00
|
|
|
|
2021-06-22 22:18:12 +00:00
|
|
|
/// Base URL or website root directory to check relative URLs
|
2022-02-18 09:29:49 +00:00
|
|
|
/// e.g. https://example.com or `/path/to/public`
|
2021-06-22 22:18:12 +00:00
|
|
|
#[structopt(short, long, parse(try_from_str = parse_base))]
|
2020-10-21 00:10:25 +00:00
|
|
|
#[serde(default)]
|
2021-06-22 22:18:12 +00:00
|
|
|
pub(crate) base: Option<Base>,
|
2020-10-26 08:23:45 +00:00
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
/// Basic authentication support. E.g. `username:password`
|
|
|
|
|
#[structopt(long)]
|
2020-10-26 08:23:45 +00:00
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) basic_auth: Option<String>,
|
2020-10-26 22:31:31 +00:00
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
/// GitHub API token to use when checking github.com links, to avoid rate limiting
|
2022-01-06 08:54:03 +00:00
|
|
|
#[structopt(long, env = "GITHUB_TOKEN", hide_env_values = true)]
|
2020-10-26 22:31:31 +00:00
|
|
|
#[serde(default)]
|
2022-02-13 12:53:46 +00:00
|
|
|
pub(crate) github_token: Option<SecretString>,
|
2020-12-02 22:28:37 +00:00
|
|
|
|
|
|
|
|
/// Skip missing input files (default is to error if they don't exist)
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) skip_missing: bool,
|
2020-12-02 22:28:37 +00:00
|
|
|
|
2022-03-26 09:42:56 +00:00
|
|
|
/// Find links in verbatim sections like `pre`- and `code` blocks
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) include_verbatim: bool,
|
|
|
|
|
|
2020-12-02 22:28:37 +00:00
|
|
|
/// Ignore case when expanding filesystem path glob inputs
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) glob_ignore_case: bool,
|
2020-12-14 00:15:14 +00:00
|
|
|
|
|
|
|
|
/// Output file of status report
|
|
|
|
|
#[structopt(short, long, parse(from_os_str))]
|
|
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) output: Option<PathBuf>,
|
2020-12-14 00:15:14 +00:00
|
|
|
|
2021-11-17 23:44:48 +00:00
|
|
|
/// Output format of final status report (compact, detailed, json, markdown)
|
|
|
|
|
#[structopt(short, long, default_value = "compact")]
|
2020-12-14 00:15:14 +00:00
|
|
|
#[serde(default)]
|
Major refactor of codebase (#208)
- The binary component and library component are separated as two
packages in the same workspace.
- `lychee` is the binary component, in `lychee-bin/*`.
- `lychee-lib` is the library component, in `lychee-lib/*`.
- Users can now install only the `lychee-lib`, instead of both
components, that would require fewer dependencies and faster
compilation.
- Dependencies for each component are adjusted and updated. E.g.,
no CLI dependencies for `lychee-lib`.
- CLI tests are only moved to `lychee`, as it has nothing to do
with the library component.
- `Status::Error` is refactored to contain dedicated error enum,
`ErrorKind`.
- The motivation is to delay the formatting of errors to strings.
Note that `e.to_string()` is not necessarily cheap (though
trivial in many cases). The formatting is no delayed until the
error is needed to be displayed to users. So in some cases, if
the error is never used, it means that it won't be formatted at
all.
- Replaced `regex` based matching with one of the following:
- Simple string equality test in the case of 'false positivie'.
- URL parsing based test, in the case of extracting repository and
user name for GitHub links.
- Either cases would be much more efficient than `regex` based
matching. First, there's no need to construct a state machine for
regex. Second, URL is already verified and parsed on its creation,
and extracting its components is fairly cheap. Also, this removes
the dependency on `lazy-static` in `lychee-lib`.
- `types` module now has a sub-directory, and its components are now
separated into their own modules (in that sub-directory).
- `lychee-lib::test_utils` module is only compiled for tests.
- `wiremock` is moved to `dev-dependency` as it's only needed for
`test` modules.
- Dependencies are listed in alphabetical order.
- Imports are organized in the following fashion:
- Imports from `std`
- Imports from 3rd-party crates, and `lychee-lib`.
- Imports from `crate::*` or `super::*`.
- No glob import.
- I followed suggestion from `cargo clippy`, with `clippy::all` and
`clippy:pedantic`.
Co-authored-by: Lucius Hu <lebensterben@users.noreply.github.com>
2021-04-14 23:24:11 +00:00
|
|
|
pub(crate) format: Format,
|
2021-09-04 01:21:54 +00:00
|
|
|
|
|
|
|
|
/// When HTTPS is available, treat HTTP links as errors
|
|
|
|
|
#[structopt(long)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub(crate) require_https: bool,
|
2020-08-14 09:43:45 +00:00
|
|
|
}
|
2020-10-21 00:10:25 +00:00
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
|
/// Load configuration from a file
|
|
|
|
|
pub(crate) fn load_from_file(path: &str) -> Result<Option<Config>> {
|
|
|
|
|
// Read configuration file
|
|
|
|
|
let result = fs::read(path);
|
|
|
|
|
|
|
|
|
|
// Ignore a file not found error
|
|
|
|
|
let contents = match result {
|
|
|
|
|
Ok(c) => c,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
return match e.kind() {
|
2020-11-25 09:40:36 +00:00
|
|
|
ErrorKind::NotFound => Ok(None),
|
2020-10-21 00:10:25 +00:00
|
|
|
_ => Err(Error::from(e)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(Some(toml::from_slice(&contents)?))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Merge the configuration from TOML into the CLI configuration
|
2020-12-02 22:28:37 +00:00
|
|
|
pub(crate) fn merge(&mut self, toml: Config) {
|
2020-10-21 00:10:25 +00:00
|
|
|
fold_in! {
|
|
|
|
|
// Destination and source configs
|
|
|
|
|
self, toml;
|
|
|
|
|
|
|
|
|
|
// Keys with defaults to assign
|
|
|
|
|
verbose: false;
|
2022-01-14 14:25:51 +00:00
|
|
|
cache: false;
|
2021-02-21 16:19:32 +00:00
|
|
|
no_progress: false;
|
2022-01-07 00:03:10 +00:00
|
|
|
max_redirects: DEFAULT_MAX_REDIRECTS;
|
|
|
|
|
max_retries: DEFAULT_MAX_RETRIES;
|
2022-02-07 22:17:50 +00:00
|
|
|
max_concurrency: DEFAULT_MAX_CONCURRENCY;
|
|
|
|
|
max_cache_age: humantime::parse_duration(DEFAULT_MAX_CACHE_AGE).unwrap();
|
2020-10-21 00:10:25 +00:00
|
|
|
threads: None;
|
2022-01-07 00:03:10 +00:00
|
|
|
user_agent: DEFAULT_USER_AGENT;
|
2020-10-21 00:10:25 +00:00
|
|
|
insecure: false;
|
2021-04-26 16:24:54 +00:00
|
|
|
scheme: Vec::<String>::new();
|
2020-10-25 12:41:06 +00:00
|
|
|
include: Vec::<String>::new();
|
2020-10-21 00:10:25 +00:00
|
|
|
exclude: Vec::<String>::new();
|
2021-09-01 15:37:31 +00:00
|
|
|
exclude_file: Vec::<String>::new();
|
2020-10-21 00:10:25 +00:00
|
|
|
exclude_all_private: false;
|
|
|
|
|
exclude_private: false;
|
|
|
|
|
exclude_link_local: false;
|
|
|
|
|
exclude_loopback: false;
|
2021-02-10 10:58:04 +00:00
|
|
|
exclude_mail: false;
|
2020-10-21 00:10:25 +00:00
|
|
|
headers: Vec::<String>::new();
|
|
|
|
|
accept: None;
|
2022-02-24 11:24:57 +00:00
|
|
|
timeout: DEFAULT_TIMEOUT_SECS;
|
|
|
|
|
retry_wait_time: DEFAULT_RETRY_WAIT_TIME_SECS;
|
2022-02-07 22:17:50 +00:00
|
|
|
method: DEFAULT_METHOD;
|
2021-06-22 22:18:12 +00:00
|
|
|
base: None;
|
2020-10-26 08:23:45 +00:00
|
|
|
basic_auth: None;
|
2020-12-02 22:28:37 +00:00
|
|
|
skip_missing: false;
|
2022-03-26 09:42:56 +00:00
|
|
|
include_verbatim: false;
|
2020-12-02 22:28:37 +00:00
|
|
|
glob_ignore_case: false;
|
2020-12-14 00:15:14 +00:00
|
|
|
output: None;
|
2021-09-04 01:21:54 +00:00
|
|
|
require_https: false;
|
2020-10-21 00:10:25 +00:00
|
|
|
}
|
2022-02-13 12:53:46 +00:00
|
|
|
|
|
|
|
|
if self
|
|
|
|
|
.github_token
|
|
|
|
|
.as_ref()
|
|
|
|
|
.map(ExposeSecret::expose_secret)
|
|
|
|
|
.is_none()
|
|
|
|
|
&& toml
|
|
|
|
|
.github_token
|
|
|
|
|
.as_ref()
|
|
|
|
|
.map(ExposeSecret::expose_secret)
|
|
|
|
|
.is_some()
|
|
|
|
|
{
|
|
|
|
|
self.github_token = toml.github_token;
|
|
|
|
|
}
|
2020-10-21 00:10:25 +00:00
|
|
|
}
|
|
|
|
|
}
|