-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.py
56 lines (44 loc) · 1.53 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# generate cli docs
import re
from pathlib import Path
# cli
from mkdocs_click._docs import make_command_docs
from grid.cli.__main__ import main
r = make_command_docs(prog_name="grid", command=main, depth=1, style="table")
# parse admonition
# https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/admonition.py
a = re.compile("!!! [w+]+[\n]*[.;w\[!\]()@:/.,\-\"*?\\']*[\n]{0,2}")
R = re.compile(r'(?:^|\n)!!! ?([\w\-]+(?: +[\w\-]+)*)(?: +"(.*?)")? *(?:\n|$)')
RE_SPACES = re.compile(" +")
def to_id(arg: str):
return "{#" + arg.replace(".", "-") + "}"
INTRO = """---
sidebar_position: 5
title: GRID CLI REFERENCE
sidebar_label: GRID CLI REFERENCE
---
"""
with open("docs/cli.md", "w") as _cli:
next(r)
_cli.write(INTRO)
for row in r:
row = row.replace('_required', '')
if '\n' in row:
row = row.replace('\n', "")
if row.startswith("### "):
row = row.replace("### ", "## grid ")
if row.startswith("#### "):
row = row.replace("#### ", "### ")
if '`g2.8xlarge,g3.16xlarge,' in row:
row = row.replace(",", ", ")
row = row.replace("<", "`<").replace(">", ">`")
_cli.write(row + "\n")
# changelog
with open("docs/changelog.md", "w") as w:
with open("changelog/header.md") as f:
w.write(f.read())
for file in sorted(Path("changelog").glob("*.md"), reverse=True):
if file.name != "header.md":
with open(file) as f:
w.write(f.read())
w.write('\n')