Files
edx-platform/scripts/paver_autocomplete.sh
Kyle McCormick cd24534653 build: run ShellCheck in CI (#31809)
build: run ShellCheck

Adds a ShellCheck check to edx-platform PRs and master,
using the shared workflow & template from the .github repo.
This will become a "required" check once it passes for 2 straight weeks on master.

Brings all existing shell scripts into compliance with ShellCheck.
2023-03-10 16:10:56 +00:00

90 lines
2.1 KiB
Bash

# shellcheck disable=all
# ^ Paver in edx-platform is on the way out
# (https://github.com/openedx/edx-platform/issues/31798)
# so we're not going to bother fixing these shellcheck
# violations.
# Courtesy of Gregory Nicholas
_subcommand_opts()
{
local awkfile command cur usage
command=$1
cur=${COMP_WORDS[COMP_CWORD]}
awkfile=/tmp/paver-option-awkscript-$$.awk
echo '
BEGIN {
opts = "";
}
{
for (i = 1; i <= NF; i = i + 1) {
# Match short options (-a, -S, -3)
# or long options (--long-option, --another_option)
# in output from paver help [subcommand]
if ($i ~ /^(-[A-Za-z0-9]|--[A-Za-z][A-Za-z0-9_-]*)/) {
opt = $i;
# remove trailing , and = characters.
match(opt, "[,=]");
if (RSTART > 0) {
opt = substr(opt, 0, RSTART);
}
opts = opts " " opt;
}
}
}
END {
print opts
}' > $awkfile
usage=`paver help $command`
options=`echo "$usage"|awk -f $awkfile`
COMPREPLY=( $(compgen -W "$options" -- "$cur") )
}
_paver()
{
local cur prev
COMPREPLY=()
# Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"
# Build a list of the available tasks from: `paver --help --quiet`
local cmds=$(paver -hq | awk '/^ ([a-zA-Z][a-zA-Z0-9_]+)/ {print $1}')
subcmd="${COMP_WORDS[1]}"
# Generate possible matches and store them in the
# array variable COMPREPLY
if [[ -n $subcmd ]]
then
if [[ ${#COMP_WORDS[*]} == 3 ]]
then
_subcommand_opts $subcmd
return 0
else
if [[ "$cur" == -* ]]
then
_subcommand_opts $subcmd
return 0
else
COMPREPLY=( $(compgen -o nospace -- "$cur") )
fi
fi
fi
if [[ ${#COMP_WORDS[*]} == 2 ]]
then
COMPREPLY=( $(compgen -W "${cmds}" -- "$cur") )
fi
}
# Assign the auto-completion function for our command.
complete -F _paver -o default paver