diff --git a/README.md b/README.md index a7ec746e85..47a26be789 100644 --- a/README.md +++ b/README.md @@ -484,8 +484,11 @@ Options: [default: get] - -b, --base - Base URL or website root directory to check relative URLs e.g. or `/path/to/public` + --base + Deprecated; use `--base-url` instead + + -b, --base-url + Base URL used to resolve relative URLs during link checking Example: --root-dir Root path to use when checking absolute local links, must be an absolute path diff --git a/fixtures/configs/smoketest.toml b/fixtures/configs/smoketest.toml index 5cd5e3b95c..3dc229fa11 100644 --- a/fixtures/configs/smoketest.toml +++ b/fixtures/configs/smoketest.toml @@ -80,7 +80,7 @@ remap = [ ] # Base URL or website root directory to check relative URLs. -base = "https://example.com" +base_url = "https://example.com" # HTTP basic auth support. This will be the username and password passed to the # authorization HTTP header. See diff --git a/lychee-bin/src/client.rs b/lychee-bin/src/client.rs index d1b982dc26..7c9e81270b 100644 --- a/lychee-bin/src/client.rs +++ b/lychee-bin/src/client.rs @@ -55,7 +55,7 @@ pub(crate) fn create(cfg: &Config, cookie_jar: Option<&Arc>) - ClientBuilder::builder() .remaps(remaps) - .base(cfg.base.clone()) + .base(cfg.base_url.clone()) .includes(includes) .excludes(excludes) .exclude_all_private(cfg.exclude_all_private) diff --git a/lychee-bin/src/main.rs b/lychee-bin/src/main.rs index fea752a271..6c0b48b733 100644 --- a/lychee-bin/src/main.rs +++ b/lychee-bin/src/main.rs @@ -177,6 +177,13 @@ fn load_config() -> Result { warn!("WARNING: `--exclude-mail` is deprecated and will soon be removed; E-Mail is no longer checked by default. Use `--include-mail` to enable E-Mail checking."); } + // TODO: Remove this warning and the parameter with 1.0 + if opts.config.base.is_some() { + warn!( + "WARNING: `--base` is deprecated and will soon be removed; use `--base-url` instead." + ); + } + // Load excludes from file for path in &opts.config.exclude_file { let file = File::open(path)?; @@ -288,7 +295,18 @@ fn underlying_io_error_kind(error: &Error) -> Option { async fn run(opts: &LycheeOptions) -> Result { let inputs = opts.inputs()?; - let mut collector = Collector::new(opts.config.root_dir.clone(), opts.config.base.clone())? + // TODO: Remove this section after `--base` got removed with 1.0 + let base = match (opts.config.base.clone(), opts.config.base_url.clone()) { + (None, None) => None, + (Some(base), None) => Some(base), + (None, Some(base_url)) => Some(base_url), + (Some(_base), Some(base_url)) => { + warn!("WARNING: Both, `--base` and `--base-url` are set. Using `base-url` and ignoring `--base` (as it's deprecated)."); + Some(base_url) + } + }; + + let mut collector = Collector::new(opts.config.root_dir.clone(), base)? .skip_missing_inputs(opts.config.skip_missing) .skip_hidden(!opts.config.hidden) .skip_ignored(!opts.config.no_ignore) diff --git a/lychee-bin/src/options.rs b/lychee-bin/src/options.rs index be47b5e284..25edf5e585 100644 --- a/lychee-bin/src/options.rs +++ b/lychee-bin/src/options.rs @@ -449,11 +449,16 @@ separated list of accepted status codes. This example will accept 200, 201, #[serde(default = "method")] pub(crate) method: String, - /// Base URL or website root directory to check relative URLs - /// e.g. or `/path/to/public` + /// Deprecated; use `--base-url` instead + #[arg(long, value_parser = parse_base)] + #[serde(skip)] + pub(crate) base: Option, + + /// Base URL used to resolve relative URLs during link checking + /// Example: #[arg(short, long, value_parser= parse_base)] #[serde(default)] - pub(crate) base: Option, + pub(crate) base_url: Option, /// Root path to use when checking absolute local links, /// must be an absolute path @@ -568,7 +573,7 @@ impl Config { timeout: DEFAULT_TIMEOUT_SECS; retry_wait_time: DEFAULT_RETRY_WAIT_TIME_SECS; method: DEFAULT_METHOD; - base: None; + base_url: None; basic_auth: None; skip_missing: false; include_verbatim: false; diff --git a/lychee-bin/tests/cli.rs b/lychee-bin/tests/cli.rs index 750b9763d4..b499fe03cf 100644 --- a/lychee-bin/tests/cli.rs +++ b/lychee-bin/tests/cli.rs @@ -383,7 +383,7 @@ mod cli { let dir = fixtures_path().join("resolve_paths"); cmd.arg("--offline") - .arg("--base") + .arg("--base-url") .arg(&dir) .arg(dir.join("index.html")) .env_clear() @@ -419,7 +419,7 @@ mod cli { cmd.arg("--offline") .arg("--root-dir") .arg("/resolve_paths") - .arg("--base") + .arg("--base-url") .arg(&dir) .arg(dir.join("resolve_paths").join("index.html")) .env_clear() diff --git a/lychee.example.toml b/lychee.example.toml index 034907016c..bd0e778bb5 100644 --- a/lychee.example.toml +++ b/lychee.example.toml @@ -75,7 +75,7 @@ header = ["name=value", "other=value"] remap = ["https://example.com http://example.invalid"] # Base URL or website root directory to check relative URLs. -base = "https://example.com" +base_url = "https://example.com" # HTTP basic auth support. This will be the username and password passed to the # authorization HTTP header. See