From 5db0adda77ec186859e19b29c9a842d39a3e8c0f Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Mon, 7 Sep 2020 15:19:16 +0200 Subject: [PATCH] Add docker.github.io documentation checker and update doc message Signed-off-by: Ulysses Souza --- compose/cli/main.py | 6 +++--- script/docs/check_help.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 script/docs/check_help.py diff --git a/compose/cli/main.py b/compose/cli/main.py index acac12246..7ec09bea2 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -310,14 +310,14 @@ class TopLevelCommand: Options: --resolve-image-digests Pin image tags to digests. - --no-interpolate Don't interpolate environment variables + --no-interpolate Don't interpolate environment variables. -q, --quiet Only validate the configuration, don't print anything. --services Print the service names, one per line. --volumes Print the volume names, one per line. --hash="*" Print the service config hash, one per line. Set "service1,service2" for a list of specified services - or use the wildcard symbol to display all services + or use the wildcard symbol to display all services. """ additional_options = {'--no-interpolate': options.get('--no-interpolate')} @@ -1005,7 +1005,7 @@ class TopLevelCommand: --build Build images before starting containers. --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d. - --attach-dependencies Attach to dependent containers + --attach-dependencies Attach to dependent containers. -t, --timeout TIMEOUT Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10) diff --git a/script/docs/check_help.py b/script/docs/check_help.py new file mode 100755 index 000000000..0904f00c4 --- /dev/null +++ b/script/docs/check_help.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import glob +import os.path +import re +import subprocess + +USAGE_RE = re.compile(r"```.*?\nUsage:.*?```", re.MULTILINE | re.DOTALL) +USAGE_IN_CMD_RE = re.compile(r"^Usage:.*", re.MULTILINE | re.DOTALL) + +HELP_CMD = "docker run --rm docker/compose:latest %s --help" + +for file in glob.glob("compose/reference/*.md"): + with open(file) as f: + data = f.read() + if not USAGE_RE.search(data): + print("Not a command:", file) + continue + subcmd = os.path.basename(file).replace(".md", "") + if subcmd == "overview": + continue + print(f"Found {subcmd}: {file}") + help_cmd = HELP_CMD % subcmd + help = subprocess.check_output(help_cmd.split()) + help = help.decode("utf-8") + help = USAGE_IN_CMD_RE.findall(help)[0] + help = help.strip() + data = USAGE_RE.sub(f"```none\n{help}\n```", data) + with open(file, "w") as f: + f.write(data)