Files
ardupilot/Tools/completion/completion.bash
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

13 lines
455 B
Bash
Executable File

#!/usr/bin/env bash
# shellcheck source-path=SCRIPTDIR
_AP_COMPLETION_DIR=$(builtin cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)
# shellcheck source=bash/_waf
source "$_AP_COMPLETION_DIR/bash/_waf"
# shellcheck source=bash/_sim_vehicle
source "$_AP_COMPLETION_DIR/bash/_sim_vehicle"
# shellcheck source=bash/_ap_bin
source "$_AP_COMPLETION_DIR/bash/_ap_bin"
# shellcheck source=bash/_ap_autotest
source "$_AP_COMPLETION_DIR/bash/_ap_autotest"