From 08f71bc55ed6e8ace6133df9f7d00483c1b5d232 Mon Sep 17 00:00:00 2001 From: Sudip Bhattarai Date: Thu, 13 Jun 2024 10:46:41 +0545 Subject: [PATCH] Add doc for enbsubst.py --- tests/test-infrastructure/scripts/envsubst.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test-infrastructure/scripts/envsubst.py b/tests/test-infrastructure/scripts/envsubst.py index eb60c4c8b..ff4700ff7 100755 --- a/tests/test-infrastructure/scripts/envsubst.py +++ b/tests/test-infrastructure/scripts/envsubst.py @@ -1,8 +1,21 @@ #!/usr/bin/python3 +""" +NAME + envsubst.py - substitutes environment variables in bash format strings + +DESCRIPTION + envsubst.py is upgrade of POSIX command `envsubst` + + supported syntax: + normal - ${VARIABLE1} + with default - ${VARIABLE1:-somevalue} +""" + import os import re import sys + def envsubst(template_str, env=os.environ): """Substitute environment variables in the template string, supporting default values.""" pattern = re.compile(r'\$\{([^}:\s]+)(?::-(.*?))?\}') @@ -14,6 +27,7 @@ def replace(match): return pattern.sub(replace, template_str) + def main(): if len(sys.argv) > 2: print("Usage: python envsubst.py [template_file]") @@ -30,5 +44,6 @@ def main(): print(result) + if __name__ == "__main__": main()