Skip to content

Commit

Permalink
Generate docs using Python instead of Bash
Browse files Browse the repository at this point in the history
The reason for this change is that Bash script has unexpected failures
during execution in Docker on Mac. Also, as Python is already used, it
won't introduce updates to the CI environment.
  • Loading branch information
extsoft committed Feb 9, 2020
1 parent 9d453ce commit 1c6d816
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .workflows/ci-pipeline.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipeline() {
--exclude=docs/*.png \
--verbose --file=/dev/null || fail "Unreadable todo is identified."
(
.workflows/docs-generation.bash
python .workflows/docs.py
git update-index --really-refresh
git diff-index --quiet HEAD --
) || fail "The documentation is not up to date. Please run './.workflows/docs-generation.bash' and commit the changes"
Expand Down
65 changes: 0 additions & 65 deletions .workflows/docs-generation.bash

This file was deleted.

52 changes: 52 additions & 0 deletions .workflows/docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""The script generates 'docs/commands.md' file."""
import subprocess

from typing import List, Sequence


def output(raw) -> str:
return raw.decode("utf-8")


def command_output(command) -> List[str]:
return output(subprocess.check_output(command)).splitlines()


def header(command: str):
return f"# `{command}`\n"


def normalize_command_line(line: str):
if line.startswith("usage:"):
return f"```bash\n{line}\n```\n"
return f"{line}\n"


def body() -> Sequence[str]:
print("Generate documentation...")
data = []
print("Explain 'git-elegant'...")
data.append(header("git-elegant"))
data.append("```bash\n")
data.extend(map(lambda line: f"{line}\n", command_output("bin/git-elegant")))
data.append("```\n\n")
for command in command_output(["bin/git-elegant", "show-commands"]):
print(f"Explain 'git-elegant {command}'...")
data.append(header(command))
data.extend(
map(
normalize_command_line,
command_output(["bin/git-elegant", command, "--help"]),
)
)
return data[:-1]


def save_text(documentation: Sequence[str], destination: str) -> None:
print("Write documentation to", destination)
with open(destination, "w") as doc:
doc.writelines(documentation)


if __name__ == "__main__":
save_text(body(), "docs/commands.md")
2 changes: 1 addition & 1 deletion workflows
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ testing() {
}

generate-docs() {
.workflows/docs-generation.bash
python .workflows/docs.py
}

preview-docs() {
Expand Down

0 comments on commit 1c6d816

Please sign in to comment.