diff mbox series

[bpf-next,v2,4/5] bpftool: Update bash completion for "bpftool feature" command

Message ID 20200221031702.25292-5-mrostecki@opensuse.org
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpftool: Make probes which emit dmesg warnings optional | expand

Commit Message

Michal Rostecki Feb. 21, 2020, 3:16 a.m. UTC
Update bash completion for "bpftool feature" command with the new
argument: "full".

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
---
 tools/bpf/bpftool/bash-completion/bpftool | 27 ++++++++++++++++-------
 1 file changed, 19 insertions(+), 8 deletions(-)

Comments

Quentin Monnet Feb. 21, 2020, 11:29 a.m. UTC | #1
2020-02-21 04:16 UTC+0100 ~ Michal Rostecki <mrostecki@opensuse.org>
> Update bash completion for "bpftool feature" command with the new
> argument: "full".
> 
> Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
> ---
>   tools/bpf/bpftool/bash-completion/bpftool | 27 ++++++++++++++++-------
>   1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index 754d8395e451..f2bcc4bacee2 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool
> @@ -981,14 +981,25 @@ _bpftool()
>           feature)
>               case $command in
>                   probe)
> -                    [[ $prev == "prefix" ]] && return 0
> -                    if _bpftool_search_list 'macros'; then
> -                        COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) )
> -                    else
> -                        COMPREPLY+=( $( compgen -W 'macros' -- "$cur" ) )
> -                    fi
> -                    _bpftool_one_of_list 'kernel dev'
> -                    return 0
> +                    case $prev in
> +                        $command)
> +                            COMPREPLY+=( $( compgen -W 'kernel dev full macros' -- \
> +                                "$cur" ) )
> +                            return 0
> +                            ;;
> +                        prefix)
> +                            return 0
> +                            ;;
> +                        macros)
> +                            COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) )
> +                            return 0

I have not tested, but I think because of the "return 0" this will 
propose only "prefix" after "macros". But "kernel" or "dev" should also 
be in the list.

Maybe just add "_bpftool_once_attr 'full'" under the 
"_bpftool_one_of_list 'kernel dev'" instead of changing to the "case 
$prev in" structure?

> +                            ;;
> +                        *)
> +                            _bpftool_one_of_list 'kernel dev'
> +                            _bpftool_once_attr 'full macros'
> +                            return 0
> +                            ;;
> +                    esac
>                       ;;
>                   *)
>                       [[ $prev == $object ]] && \
>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 754d8395e451..f2bcc4bacee2 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -981,14 +981,25 @@  _bpftool()
         feature)
             case $command in
                 probe)
-                    [[ $prev == "prefix" ]] && return 0
-                    if _bpftool_search_list 'macros'; then
-                        COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) )
-                    else
-                        COMPREPLY+=( $( compgen -W 'macros' -- "$cur" ) )
-                    fi
-                    _bpftool_one_of_list 'kernel dev'
-                    return 0
+                    case $prev in
+                        $command)
+                            COMPREPLY+=( $( compgen -W 'kernel dev full macros' -- \
+                                "$cur" ) )
+                            return 0
+                            ;;
+                        prefix)
+                            return 0
+                            ;;
+                        macros)
+                            COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) )
+                            return 0
+                            ;;
+                        *)
+                            _bpftool_one_of_list 'kernel dev'
+                            _bpftool_once_attr 'full macros'
+                            return 0
+                            ;;
+                    esac
                     ;;
                 *)
                     [[ $prev == $object ]] && \