-
Notifications
You must be signed in to change notification settings - Fork 1
Adding a New Command
Griffen Fargo edited this page Apr 10, 2026
·
1 revision
Step-by-step guide for extending the strut CLI with a new command.
Create lib/cmd_<name>.sh:
#!/usr/bin/env bash
# ==================================================
# cmd_<name>.sh — <Description>
# ==================================================
# Dependencies: lib/utils.sh, lib/config.sh
# Provides: cmd_<name>
set -euo pipefail
cmd_<name>() {
local stack="$1"
local env_file="$2"
shift 2
# Parse command-specific args
# ...
log "Running <name> for stack: $stack"
# Implementation
# Use run_cmd for destructive operations (supports --dry-run)
# Use validate_env_file before accessing env vars
# Use build_ssh_opts for SSH commands
# Use resolve_compose_cmd for Docker Compose commands
}Add to the strut file, in the source block:
source "$LIB/cmd_<name>.sh"Add to the case "$COMMAND" block in strut:
<name>) cmd_<name> "$STACK" "$ENV_FILE" "${CMD_ARGS[@]}" ;;Add to the usage() function in strut:
echo " <name> [--env <name>] [options] Description of command"Create tests/test_<name>.bats:
#!/usr/bin/env bats
setup() {
TEST_TMP="$(mktemp -d)"
# Override fail so it doesn't exit the test runner
fail() { echo "$1" >&2; return 1; }
}
teardown() {
rm -rf "$TEST_TMP"
}
@test "<name>: basic functionality" {
# Test implementation
run some_function
[ "$status" -eq 0 ]
}-
lib/cmd_<name>.shcreated with header comment andset -euo pipefail - Sourced in
strutentrypoint - Added to dispatch
caseblock - Added to
usage()output - Tests in
tests/test_<name>.bats -
shellcheckpasses -
bats tests/passes - No hardcoded org names, service names, or paths
strut · v0.28.0 · Report an Issue
Getting Started
Core Concepts
Operations
- Deployment
- Ship and Rebuild
- GitHub Action
- Webhook Automation
- Remote Host Setup
- Provisioning
- Blue-Green Deploy
- Deploy Rollback
- Database Backups
- Secrets Management
- Stack Groups
- Lifecycle Hooks
- Notifications
- Key Rotation
- Drift Detection
- Domain and SSL
- Certificate Management
- Gateway Management
- Monitoring
- Volume Management
Advanced
- Security Posture
- VPS Audit and Migration
- Stack Validation
- Data Anonymization
- Debugging
- Local Development
Extending
Contributing