To refactor the run.sh and its downstream scripts (e.g., commandline.sh, logger.sh, helpers.sh) to align with the Google Shell Style Guide, improving maintainability, reliability, and predictability.
- Add
set -euo pipefailto the top of all entry-point and primary scripts. - Why: To ensure the script fails immediately on errors, unset variables, or pipeline failures, preventing "silent failures."
- Constants (Global): Use
UPPER_S**_CASE(e.g.,KUBECTL_VERSION). - Global Variables: Use
UPPER_S_CASE(e.g.,RUN_DIR,APPS_DIR). - Local Variables: Use
lowercase_snake_case(e.g.,config_path,app_name). - Functions: Use
lowercase_snake_case.
- Implement a unified logging/error reporting pattern across all scripts.
- Ensure all error messages are redirected to
stderr(>&2).
- Simplify the macOS Bash 4+ re-execution logic.
- Replace brittle
cd ... && pwdwith modern, safer path resolution.
- Standardize
PATHmanipulation to ensure predictable behavior on both macOS (Homebrew) and Linux.
- Audit
load_config_from_file: Convert allconfig_...variables from global scope tolocalscope. - Audit
get_options: Ensure all parsing variables arelocal. - Why: To prevent "variable leakage" where a function accidentally modifies the global state of the deployment process.
- Standardize all function headers to include:
- Description: What the function does.
- Arguments:
$1,$2, etc., with descriptions. - Returns/Outputs: Success/failure indicators.
- Eliminate
eval: Replaceeval "export $var_name=\"\$value\""with safer assignment methods (e.g.,printf -vor direct assignment) to prevent injection risks. - Argument Parsing: Refactor
get_optionsto use a more robust, standardizedgetoptspattern.
- Run
shellcheckon every modified file to validate adherence to the style guide and catch syntax errors.
- Regression Test 1: Execute
deploymode to ensurePATHandPYTHON3lookups remain functional. - Regression Test 2: Execute
cleanallmode to ensure the logic for resource deletion is not disrupted by variable scoping changes. - Regression Test 3: Verify
pipx/crudiniinstallation logic on macOS.
- Phase 1: Apply
set -eandlocalvariable scoping (Highest impact on stability). - Phase 2: Standardize Naming and Documentation.
- Phase 3: Refactor
evaland complex logic. - Phase 4: Final
shellcheckand functional validation.