-
Notifications
You must be signed in to change notification settings - Fork 0
Code Conventions
Griffen Fargo edited this page Apr 11, 2026
·
2 revisions
Standards for shell modules, function naming, error handling, configuration access, and testing patterns used across the strut codebase.
Every lib module must:
- Start with
#!/usr/bin/env bash - Include
set -euo pipefail - Have a header comment block: module name, description, dependencies, provided functions
- Document required sourced dependencies (e.g.,
# Requires: lib/utils.sh sourced first)
| Pattern | Use | Example |
|---|---|---|
cmd_<name>() |
Command handlers |
cmd_deploy() in lib/cmd_deploy.sh
|
_prefixed() |
Internal helpers | _resolve_script_dir() |
descriptive_name() |
Public library functions | find_project_root() |
| Function | Behavior |
|---|---|
fail "msg" |
Fatal — exits 1 to stderr |
warn "msg" |
Non-fatal — continues to stdout |
log "msg" |
Informational with [strut] prefix |
ok "msg" |
Success with checkmark |
Never use bare || return 1 without a message.
- All config is read from
strut.confvialib/config.sh - Never hardcode org names, registry types, branch names, or service names
- Per-stack config comes from
services.conf,required_vars,volume.conf,repos.conf - Defaults are defined in
load_strut_config()only
Always use build_ssh_opts for consistent SSH option building. Always use validate_env_file before accessing env vars.
Always use resolve_compose_cmd for consistent project naming. Never construct compose commands manually.
- Wrap destructive operations with
run_cmdorrun_cmd_eval - Check
DRY_RUN=truefor early exit with execution plan display
- File naming:
tests/test_<module>.bats - Use
setup()/teardown()withTEST_TMPfor temp dirs - Source
test_helper/common.bashfor shared helpers - Override
fail()in tests:fail() { echo "$1" >&2; return 1; } - Property tests: 100 iterations with randomized inputs
- Static analysis tests: grep-based checks for hardcoded references
strut · v0.1.0 · Report an Issue
Getting Started
Core Concepts
Operations
- Deployment
- Remote Host Setup
- Blue-Green Deploy
- Deploy Rollback
- Database Backups
- Stack Groups
- Lifecycle Hooks
- Notifications
- Key Rotation
- Drift Detection
- Domain and SSL
- Monitoring
- Volume Management
Advanced
- Security Posture
- VPS Audit and Migration
- Stack Validation
- Data Anonymization
- Debugging
- Local Development
Extending
Contributing