Re: [PATCH bpf-next v2 3/3] bpftool: Add bash completion for token argument

From: Tao Chen
Date: Tue Jul 22 2025 - 12:36:17 EST


在 2025/7/22 23:02, Quentin Monnet 写道:
2025-07-22 20:09 UTC+0800 ~ Tao Chen <chen.dylane@xxxxxxxxx>
This commit updates the bash completion script with the new token
argument.
$ bpftool
batch cgroup gen iter map perf struct_ops
btf feature help link net prog token


This is a terrible example, offering "token" as completion for just
"bpftool [tab]" works without this patch :) The main commands are parsed
from the output of "bpftool help" so it should work after your first
patch. In this one, we add "list", "show" and "help" for completing
"bpftool token [tab]".


As you said, how about this one? I will change it in v3, thanks.
$ bpftool token
help list show



Signed-off-by: Tao Chen <chen.dylane@xxxxxxxxx>
---
tools/bpf/bpftool/bash-completion/bpftool | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index a759ba24471..527bb47ac46 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -1215,6 +1215,17 @@ _bpftool()
;;
esac
;;
+ token)
+ case $command in
+ show|list)
+ return 0
+ ;;
+ *)
+ [[ $prev == $object ]] && \
+ COMPREPLY=( $( compgen -W 'help show list' -- "$cur" ) )
+ ;;
+ esac
+ ;;
esac
} &&
complete -F _bpftool bpftool


Other than the example in the description, this looks good.

Reviewed-by: Quentin Monnet <qmo@xxxxxxxxxx>

Thanks


--
Best Regards
Tao Chen