#!/usr/bin/env python3
"""Build README for GitHub and crates.io.
This script uses Hurl doc to generate README suitable for GitHub and crates.io
Examples:
$ python3 bin/docs/build_readme.py github > README.md
$ python3 bin/docs/build_readme.py crates > packages/hurl/README.md
"""
import os
import re
import sys
from pathlib import Path
from textwrap import dedent
from markdown import parse_markdown, MarkdownDoc
def main(dest: str) -> int:
header: str
if dest == "github":
header = dedent(
"""\
[![deploy status](https://github.com/Orange-OpenSource/hurl/workflows/test/badge.svg)](https://github.com/Orange-OpenSource/hurl/actions)
[![coverage](https://Orange-OpenSource.github.io/hurl/coverage/badges/flat.svg)](https://Orange-OpenSource.github.io/hurl/coverage)
[![Crates.io](https://img.shields.io/crates/v/hurl.svg)](https://crates.io/crates/hurl)
[![documentation](https://img.shields.io/badge/-documentation-ff0288)](https://hurl.dev)
"""
)
elif dest == "crates":
header = dedent(
"""\
[![deploy status](https://github.com/Orange-OpenSource/hurl/workflows/test/badge.svg)](https://github.com/Orange-OpenSource/hurl/actions)
[![coverage](https://Orange-OpenSource.github.io/hurl/coverage/badges/flat.svg)](https://Orange-OpenSource.github.io/hurl/coverage)
[![Crates.io](https://img.shields.io/crates/v/hurl.svg)](https://crates.io/crates/hurl)
[![documentation](https://img.shields.io/badge/-documentation-ff0288)](https://hurl.dev)
"""
)
else:
sys.stderr.write("build_readme.py [github, crates]\n")
return os.EX_USAGE
header_md = parse_markdown(text=header)
home = Path("docs/home.md").read_text()
# We adapt the "Why Hurl" part to transform h2 tag back to markdown
def showcase_rep(m):
return f"