diff --git a/Makefile b/Makefile index 3c64f93354..96e9f0d4fd 100644 --- a/Makefile +++ b/Makefile @@ -72,3 +72,7 @@ screencast: ## Create a screencast for the docs verify: ## Verify the MSRV cargo msrv --path lychee-lib verify cargo msrv --path lychee-bin verify + +.PHONY: readme +readme: ## Updates README.md with `lychee --help` + scripts/update_readme.py diff --git a/README.md b/README.md index 3b8610adb2..57135a3b13 100644 --- a/README.md +++ b/README.md @@ -701,7 +701,7 @@ Options: -u, --user-agent User agent - [default: lychee/0.20.1] + [default: lychee/x.y.z] -v, --verbose... Set verbosity level; more output per occurrence (e.g. `-v` or `-vv`) diff --git a/scripts/update_readme.py b/scripts/update_readme.py new file mode 100755 index 0000000000..d581216b7e --- /dev/null +++ b/scripts/update_readme.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +""" +Simply updates the `lychee --help` output in the README. +""" + +import subprocess + +def main(): + new_help = subprocess.check_output('cargo run -- --help'.split(), encoding='utf-8') + version = subprocess.check_output('cargo run -- --version'.split(), encoding='utf-8').split()[-1] + + lines = new_help.strip().splitlines() + new_help = '\n'.join(line.rstrip() for line in lines) + new_help = new_help.replace(f'lychee/{version}', 'lychee/x.y.z') + + begin = '\n```help-message\n' + end = '\n```\n' + + with open('README.md', 'r') as f: + text = f.read() + before, rest = text.split(begin, 1) + _, after = rest.split(end, 1) + + with open('README.md', 'w') as f: + for part in [before, begin, new_help, end, after]: + f.write(part) + +if __name__ == "__main__": + main()