Crates.io | fixred |
lib.rs | fixred |
version | 1.1.3 |
source | src |
created_at | 2021-09-26 15:59:30.13449 |
updated_at | 2021-09-30 11:54:16.320971 |
description | Command line tool to fix outdated URLs in files with redirected ones |
homepage | https://github.com/rhysd/fixred#readme |
repository | https://github.com/rhysd/fixred |
max_upload_size | |
id | 456586 |
size | 54,722 |
fixred is a command line utility to fix outdated links in files with redirect URLs.
fixred is installed via cargo package manager. libcurl is necessary as dependency.
cargo install fixred
fixred --help
If you don't have Rust toolchain, a Docker image is also available.
docker run -it --rm rhysd/fixred:latest --help
fixred checks redirects of URLs in text files. When a URL is redirected, fixred replaces it with the redirected one. fixred ignores invalid URLs or broken links (e.g. 404) to avoid false positives in extracted URLs.
See the help output for each flags, options, and arguments.
fixred --help
Most basic usage is fixing files by passing them to command line arguments.
# Fix a file
fixred ./docs/usage.md
# Fix all files in a directory (recursively)
fixred ./docs
# Multiple paths can be passed
fixred ./README.md ./CONTRIBUTING.md ./docs
Note that fixred only handles UTF8 files. Non-UTF8 files are ignored. To know which files were ignored, try --verbose
flag.
When no argument is given, fixred reads stdin and outputs result to stdout.
cat ./docs/usage.md | fixred
Mount local directories with -v
and pass an environment variable (if necessary) with -e
. Running
the Docker image executes fixred
executable by default.
# Fix all files in ./docs
docker run -it --rm -v $(pwd):/app -e FIXRED_LOG=info rhysd/fixred:latest /app/docs
Passing the input via stdin is also possible. The result is output to stdout.
# Fix stdin and output the result to stdout
cat ./docs/usage.md | docker run -i --rm rhysd/fixred:latest
By default, fixred follows redirects repeatedly and uses the last URL to replace. However, sometimes redirecting only
once would be more useful. --shallow
flag is available for it.
For example, link to raw README file in rhysd/vim-crystal
repository (moved to vim-crystal/vim-crystal
later) is
redirected as follows.
When you want to fix 1. to 2. but don't want to fix 1. to 3., --shallow
is useful.
fixred --shallow ./README.md
When you want to fix only specific links in a file, filtering URLs with regular expressions is available. The following
example fixes URLs which starts with https://github.com/
using --extract
option.
fixred --extract '^https://github\.com/' ./docs
--ignore
option is an invert version of --extract
. URLs matched to the pattern are ignored. The following example
avoids to resolve URLs which contain hashes.
fixred --ignore '#' ./docs
By default, fixred outputs nothing when it runs successfully. For verbose log outputs, --verbose
flag or $FIXRED_LOG
i
environment variable is available.
# Outputs which file is being processed
fixred --verbose
# Or
FIXRED_LOG=info fixred ./docs
# Outputs what fixred is doing in detail
FIXRED_LOG=debug fixred ./docs
Here is an example of usage in actionlint project.
Please see the API document. And for the real world example, please see src directory.
To install as dependency, add fixred
to your Cargo.toml
file. Ensure to disable default features.
It removes all unnecessary dependencies for using this tool as library.
[dependencies]
fixred = { version = "1", default-features = false, features = [] }
Here is a small example code
use fixred::resolve::CurlResolver;
use fixred::redirect::Redirector;
fn main() {
let red = Redirector::<CurlResolver>::default();
let fixed = red.fix(std::io::stdin(), std::io::stdout()).unwrap();
eprintln!("Fixed {} link(s)", fixed);
}
Distributed under the MIT license.