Files
ardupilot/Tools/completion/bash/_waf
T
Pierre KancirandClaude Fable 5 83d9af4a54 Tools: fixes and updates for shell completion
Tools: completion: fix binary registration and vehicle-scoped completions

- _ap_bin (bash): register all SITL binaries (arducopter-heli, ardurover,
  antennatracker) instead of a duplicate arducopter entry, matching the
  zsh #compdef list.
- _ap_autotest (bash): remove the "Copter only" sed filters so test/build
  completions cover all vehicles, not just Copter.
- _ap_autotest (zsh): fix leftover debug placeholder strings in
  _wanted call for subtest completion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: sync sim_vehicle.py options with current parser

Add the many options added to sim_vehicle.py's optparse parser since
the completion scripts were last updated (build options like
--no-configure, --ubsan, --coverage; sim options like --count,
--instances, --sim-address, --enable-DDS, --osdmsp, --ekf-single,
--fram-storage, etc.) to both the bash and zsh completion scripts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: sync autotest.py zsh options with current parser

Add options introduced to autotest.py's optparse parser since the
completion script was last updated (--asan, --gdb-no-tui, --ekf-single,
--replay, --force-ahrs-type, --junit, --Werror, --coverage,
--enable-dronecan-tests, etc.).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: expand waf configure option completions

Add commonly used ./waf configure options (--upload*, --enable-*,
--disable-*, --ubsan*, --ekf-*, --osd*, --sitl-*, etc.) to both bash
and zsh completion scripts, keeping the two lists aligned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: bring bash _ap_bin option list to parity with zsh

Add the SITL/serial options (--config, --serial0..9, --sim-address,
--base-port, etc.) already present in zsh/_ap_bin to the bash version.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: generate waf command list from waf help

Parse the "Main commands" section of ./waf --help instead of
hardcoding the command list in both shells. This picks up commands
that were missing (blimp, check, check-all, replay, benchmarks,
tests, dist, install, ...) and stays current automatically. The
result is cached: per shell session in bash, via the zsh completion
cache (same policy as targets) in zsh. submodulesync and
submodule_force_clean are kept as manual entries since waf does not
list them in its help output.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: sim_vehicle: add --list-locations completion helper

Add a --list-locations option to the existing "Completion helpers"
optparse group, printing the location names from the user and
autotest locations.txt files (same lookup order as -L itself). Use
it in the bash and zsh completion scripts so -L/--location now
completes location names dynamically, like -v/--vehicle and
-f/--frame already do.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: complete SITL binary -M/--model from --list-models

The SITL binaries already expose --list-models, printing the embedded
vehicleinfo.json; use it to dynamically complete -M/--model in both
the bash and zsh completion scripts, extracting the frame names with
a small python one-liner.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: make bash completion scripts shellcheck-clean

Behaviour-preserving cleanups so shellcheck -x -s bash exits clean on
all bash completion scripts:

- SC2207/SC2086: build COMPREPLY with mapfile from compgen output and
  quote ${cur} instead of relying on word splitting.
- SC2199: use ${COMP_WORDS[*]} explicitly when matching the whole
  command line in _sim_vehicle frame lookup.
- SC2001: replace the echo|sed pipeline used to recover the calling
  program with the completion function's $1, which is the command.
- SC2034: drop the unused prev assignment in _ap_autotest.
- SC2155: declare and assign supported_vehicle_list separately.
- SC2006: use $(...) instead of backticks in completion.bash, and add
  shellcheck source= directives for the sourced scripts.
- SC2016 on '$(_parse_help "$1")' is intentional (compgen -W expands
  the string itself) and is now silenced with a justified directive.
- replace the seq-based word-reuse loops with C-style for loops.

Verified with shellcheck 0.9.0, bash -n/zsh -n on all scripts, and a
functional smoke test (registration plus dynamic -L, --board and
static option completion).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: fix option drift against the tools' help output

Cross-checking the completion scripts against the real help output
revealed:
- waf: --enable-scripting, --disable-scripting and --disable-networking
  no longer exist (the feature toggles are the generated
  --enable-SCRIPTING/--disable-Networking build options); remove them
  from both shells.
- SITL binaries: --rtscts was removed from the binaries; --start-time,
  --sysid and --slave were never added. Sync both shells and add the
  missing -S/--synthetic-clock to the zsh script.

Also anchor the shellcheck source= directives in completion.bash with
source-path=SCRIPTDIR so shellcheck -x resolves them from any working
directory.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Tools: completion: add automated staleness checker

Add check_completions.py, which extracts the long options accepted by
waf, sim_vehicle.py, autotest.py and the SITL binaries from their help
output and compares them with the options declared in the bash and zsh
completion scripts.

Stale completion entries are always errors; options missing from the
completions are errors for sim_vehicle.py, autotest.py and the
binaries, but only warnings for waf, whose completion intentionally
offers a curated subset of the hundreds of generated build options.
Machine-facing helpers such as --list-vehicle or --list-models are
excluded via per-tool allowlists, and the binary check is skipped with
a warning when no SITL binary has been built.

The script exits non-zero on failure so it can run in CI, and already
caught real drift in the waf and SITL binary completions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-20 12:38:49 +10:00

108 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
_waf()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# don't complet =
_init_completion -n = || return
# TODO: generate for waf help
opts="-h"
opts+=" -j "
opts+=" -v "
opts+=" -g "
opts+=" --debug"
opts+=" --bootloader"
opts+=" --board"
opts+=" --target"
opts+=" --upload"
opts+=" --upload-port"
opts+=" --upload-force"
opts+=" --static"
opts+=" --Werror"
opts+=" --disable-Werror"
opts+=" --default-parameters"
opts+=" --enable-sfml"
opts+=" --enable-sfml-audio"
opts+=" --enable-sfml-joystick"
opts+=" --sitl-osd"
opts+=" --sitl-rgbled"
opts+=" --sitl-flash-storage"
opts+=" --sitl-littlefs"
opts+=" --build-dates"
opts+=" --enable-scripting"
opts+=" --disable-scripting"
opts+=" --scripting-checks"
opts+=" --scripting-docs"
opts+=" --enable-dronecan-tests"
opts+=" --enable-networking-tests"
opts+=" --disable-networking"
opts+=" --num-aux-imus"
opts+=" --ekf-single"
opts+=" --ekf-double"
opts+=" --postype-single"
opts+=" --force-32bit"
opts+=" --ubsan"
opts+=" --ubsan-abort"
opts+=" --asan"
opts+=" --coverage"
opts+=" --osd"
opts+=" --osd-fonts"
opts+=" --enable-math-check-indexes"
opts+=" --enable-asserts"
opts+=" --enable-benchmarks"
opts+=" --enable-check-firmware"
opts+=" --enable-stats"
opts+=" --consistent-builds"
# generate command list from waf help (cached for the shell session)
if [ -z "$_waf_comp_commands" ]; then
_waf_comp_commands=$(./waf --help 2>/dev/null | sed -n '/^Main commands/,/^Options:/p' | sed -n 's/^ \([a-zA-Z_][a-zA-Z0-9_-]*\) *: .*/\1/p' | sed '/^conf$/d' | tr '\n' ' ')
fi
opts+=" $_waf_comp_commands"
opts+=" submodule_force_clean"
opts+=" submodulesync"
opts+=" scripting_docs"
# Prevent word reuse TODO: add -vvv case
for ((i = 0; i < COMP_CWORD; i++))
do
if [[ $opts == *"${COMP_WORDS[i]}"* ]]; then
opts=${opts//${COMP_WORDS[i]}/}
opts=${opts//--${COMP_WORDS[i]}/}
fi
done
case $prev in
--board)
opts=$(./waf list_boards | sed -e '$d')
mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
return 0
;;
esac
case $cur in
--targets=*)
cur=${cur#*=}
if [ -z "$_waf_comp_targets" ]; then
# list target without color, remove Lua embedding, remove empty and space only line, remove objs/*, remove path for lua binding, remove trailing spaces, change line return for space
_waf_comp_targets=$(./waf list -c no | sed -e '/^Embedding/d' -e '/^ *$/d' -e '/objs\//d' -e '$d' -e '/^\//d' | tr -d " " | tr '\n' ' ')
fi
opts=$_waf_comp_targets
mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
return 0
;;
esac
# shellcheck disable=SC2016 # compgen -W expands the command substitution itself
mapfile -t COMPREPLY < <(compgen -W '$(_parse_help "$1")' -- "$cur")
mapfile -t -O "${#COMPREPLY[@]}" COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
}
complete -F _waf waf