Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ docker run --rm \
# lib/actions/example.sh
#!/usr/bin/env bash
action_example() {
local args=($(filter_out_spin_arguments "$@"))

# Implementation here
filter_out_spin_arguments "$@"
local args=("${SPIN_FILTERED_ARGS[@]}")

# Implementation here, using "${args[@]}" for the filtered arguments
echo "Running example command"
}
```
Expand Down Expand Up @@ -238,9 +239,11 @@ SPIN_ENV=production spin deploy production
### Argument Filtering

```bash
# Remove Spin-specific arguments before passing to Docker
local args=($(filter_out_spin_arguments "$@"))
$COMPOSE_CMD up ${args[@]}
# Remove Spin-specific arguments before passing to Docker. The filtered
# args are returned via the SPIN_FILTERED_ARGS global.
filter_out_spin_arguments "$@"
local args=("${SPIN_FILTERED_ARGS[@]}")
$COMPOSE_CMD up "${args[@]}"
```

### Cache Management
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/exec.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
action_exec(){
$COMPOSE_CMD exec $@
$COMPOSE_CMD exec "$@"
}
3 changes: 2 additions & 1 deletion lib/actions/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
action_run(){
docker_pull_check "$@"

local args=($(filter_out_spin_arguments "$@"))
filter_out_spin_arguments "$@"
local args=("${SPIN_FILTERED_ARGS[@]}")

# Run Docker Compose without dependencies. Ensure automations and S6 logging are disabled
$COMPOSE_CMD run -e "S6_VERBOSITY=0" -e "SHOW_WELCOME_MESSAGE=false" --remove-orphans --no-deps --rm \
Expand Down
20 changes: 12 additions & 8 deletions lib/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,22 @@ export_compose_file_variable(){
fi
}

# Filters spin-only flags out of "$@". Returns the remaining arguments via
# the SPIN_FILTERED_ARGS global. bash can't return arrays through stdout
# without IFS word-splitting destroying argument boundaries at the call site.
#
# Example usage:
# filter_out_spin_arguments "$@"
# local args=("${SPIN_FILTERED_ARGS[@]}")
# $COMPOSE_CMD run ... "${args[@]}"
filter_out_spin_arguments() {
non_docker_args=(
SPIN_FILTERED_ARGS=()

local non_docker_args=(
"--skip-pull"
"--force-pull"
)

# Declare an array to hold the filtered arguments
local filtered_args=()

# Loop through all passed arguments
for arg in "$@"; do
local is_non_docker_arg=false
Expand All @@ -479,12 +486,9 @@ filter_out_spin_arguments() {
done

if ! $is_non_docker_arg; then
filtered_args+=("$arg")
SPIN_FILTERED_ARGS+=("$arg")
fi
done

# Return the filtered arguments as an array
echo "${filtered_args[@]}"
}

get_ansible_variable(){
Expand Down