From 5bfcd8894bc6546a814448bc2dac6155dd93584d Mon Sep 17 00:00:00 2001 From: Gereon Vey Date: Wed, 24 Jan 2024 14:28:22 +0100 Subject: [PATCH] add -d/--doc-urls option to only print documentation URLs --- checks-checker | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/checks-checker b/checks-checker index eb4d029..4caaf2f 100755 --- a/checks-checker +++ b/checks-checker @@ -116,6 +116,18 @@ def checkUrl(url: str) -> tuple: return (errors, warnings) +def checkGetDocuUrls(check: dict) -> int: + # Check URLs in remediation text + if 'remediation' not in check: + logging.info(f"Check {check['id']} has no remediation section, skipping check") + return 0 + urls = getUrlsFromText(check['remediation']) + logging.debug(f"{len(urls)} URLs found") + if len(urls)>0: + for url in urls: + print(url) + return 0 + def checkCheckUrls(check: dict) -> int: """Checks the URLs in a check @@ -201,6 +213,7 @@ def main(): parser.add_argument(dest='filenames', metavar='filename', nargs='+', help='checks file') parser.add_argument('-l', '--log-level', dest='loglevel', default='WARNING', action='store', help='set log level') parser.add_argument('-m', '--match', dest='match', default='', action='store', help='only process files matching this glob') + parser.add_argument('-d', '--doc-urls', dest='doc_urls', default=False, action='store_true', help='only print documentation URLs') args = parser.parse_args() # Set up logging @@ -228,7 +241,10 @@ def main(): try: checks=getChecksfromCheckFile(filename) for check in checks: - allErrors += checkCheck(check) + if args.doc_urls: + allErrors += checkGetDocuUrls(check) + else: + allErrors += checkCheck(check) except IsADirectoryError: pass