Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ Options:
-u, --user-agent <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`)
Expand Down
36 changes: 36 additions & 0 deletions scripts/update_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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]
new_help = '\n'.join(
line.replace(f'lychee/{version}', 'lychee/x.y.z').rstrip()
for line in new_help.strip().split('\n')
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit hard to read. Can we split it up into multiple steps?

lines = help_output.strip().splitlines()

normalized = [
    line.rstrip().replace(f"lychee/{version}", "lychee/x.y.z")
    for line in lines
]

new_help = "\n".join(normalized)


begin = '\n```help-message\n'
end = '\n```\n'

with open('README.md', 'r+') as f:
text = f.read()
before, after = text.split(begin, 1)
_, after = after.split(end, 1)

f.seek(0)

f.write(before)
f.write(begin)
f.write(new_help)
f.write(end)
f.write(after)

f.truncate()

if __name__ == "__main__":
main()