mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:24:31 +01:00
Currently, kunit.py has many subcommands and options, making it difficult to remember them without checking the help message. Add --list-cmds and --list-opts to kunit.py to get available commands and options, use those outputs in kunit-completion.sh to show completion. This implementation is similar to perf and tools/perf/perf-completion.sh. Example output: $ source tools/testing/kunit/kunit-completion.sh $ ./tools/testing/kunit/kunit.py [TAB][TAB] build config exec parse run $ ./tools/testing/kunit/kunit.py run --k[TAB][TAB] --kconfig_add --kernel_args --kunitconfig Link: https://lore.kernel.org/r/20260117-kunit-completion-v2-1-cabd127d0801@gmail.com Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Ryota Sakamoto <sakamo.ryota@gmail.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
34 lines
874 B
Bash
34 lines
874 B
Bash
# SPDX-License-Identifier: GPL-2.0
|
|
# bash completion support for KUnit
|
|
|
|
_kunit_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
_kunit()
|
|
{
|
|
local cur prev words cword
|
|
_init_completion || return
|
|
|
|
local script="${_kunit_dir}/kunit.py"
|
|
|
|
if [[ $cword -eq 1 && "$cur" != -* ]]; then
|
|
local cmds=$(${script} --list-cmds 2>/dev/null)
|
|
COMPREPLY=($(compgen -W "${cmds}" -- "$cur"))
|
|
return 0
|
|
fi
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
if [[ -n "${words[1]}" && "${words[1]}" != -* ]]; then
|
|
local opts=$(${script} ${words[1]} --list-opts 2>/dev/null)
|
|
COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
|
|
return 0
|
|
else
|
|
local opts=$(${script} --list-opts 2>/dev/null)
|
|
COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
|
|
return 0
|
|
fi
|
|
fi
|
|
}
|
|
|
|
complete -o default -F _kunit kunit.py
|
|
complete -o default -F _kunit kunit
|
|
complete -o default -F _kunit ./tools/testing/kunit/kunit.py
|