diff mbox series

[v2,bpf-next,12/12] bpftool: update bash-completion w/ new c option for btf dump

Message ID 20190523204222.3998365-13-andriin@fb.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series BTF-to-C converter | expand

Commit Message

Andrii Nakryiko May 23, 2019, 8:42 p.m. UTC
Add bash completion for new C btf dump option.

Cc: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/bash-completion/bpftool | 25 +++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

Comments

Quentin Monnet May 24, 2019, 9:15 a.m. UTC | #1
2019-05-23 13:42 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> Add bash completion for new C btf dump option.
> 
> Cc: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  tools/bpf/bpftool/bash-completion/bpftool | 25 +++++++++++++++++++----
>  1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index 50e402a5a9c8..5b65e0309d2a 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool
> @@ -638,11 +638,28 @@ _bpftool()
>                              esac
>                              return 0
>                              ;;
> +                        format)
> +                            COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) )
> +                            ;;
>                          *)
> -                            if [[ $cword == 6 ]] && [[ ${words[3]} == "map" ]]; then
> -                                 COMPREPLY+=( $( compgen -W 'key value kv all' -- \
> -                                     "$cur" ) )
> -                            fi
> +                            # emit extra options
> +                            case ${words[3]} in
> +                                id|file)
> +                                    if [[ $cword > 4 ]]; then

Not sure if this "if" is necessary. It seems to me that if $cword is 4
then we are just after "id" or "file" in the command line, in which case
we hit previous cases and never reach this point?

Also, reading the completion code I wonder, do we have completion for
BTF ids? It seems to me that we have nothing proposed to complete
"bpftool btf dump id <tab>". Any chance to get that in a follow-up patch?

> +                                        _bpftool_once_attr 'format'
> +                                    fi
> +                                    ;;
> +                                map|prog)
> +                                    if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then
> +                                        COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) )
> +                                    fi
> +                                    if [[ $cword > 5 ]]; then

Same remark on the "if", I do not believe it is necessary?

> +                                        _bpftool_once_attr 'format'
> +                                    fi
> +                                    ;;
> +                                *)
> +                                    ;;
> +                            esac
>                              return 0
>                              ;;
>                      esac
>
Andrii Nakryiko May 24, 2019, 6:10 p.m. UTC | #2
On Fri, May 24, 2019 at 2:15 AM Quentin Monnet
<quentin.monnet@netronome.com> wrote:
>
> 2019-05-23 13:42 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> > Add bash completion for new C btf dump option.
> >
> > Cc: Quentin Monnet <quentin.monnet@netronome.com>
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  tools/bpf/bpftool/bash-completion/bpftool | 25 +++++++++++++++++++----
> >  1 file changed, 21 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> > index 50e402a5a9c8..5b65e0309d2a 100644
> > --- a/tools/bpf/bpftool/bash-completion/bpftool
> > +++ b/tools/bpf/bpftool/bash-completion/bpftool
> > @@ -638,11 +638,28 @@ _bpftool()
> >                              esac
> >                              return 0
> >                              ;;
> > +                        format)
> > +                            COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) )
> > +                            ;;
> >                          *)
> > -                            if [[ $cword == 6 ]] && [[ ${words[3]} == "map" ]]; then
> > -                                 COMPREPLY+=( $( compgen -W 'key value kv all' -- \
> > -                                     "$cur" ) )
> > -                            fi
> > +                            # emit extra options
> > +                            case ${words[3]} in
> > +                                id|file)
> > +                                    if [[ $cword > 4 ]]; then
>
> Not sure if this "if" is necessary. It seems to me that if $cword is 4
> then we are just after "id" or "file" in the command line, in which case
> we hit previous cases and never reach this point?

Yep, you are right, removed.

>
> Also, reading the completion code I wonder, do we have completion for
> BTF ids? It seems to me that we have nothing proposed to complete
> "bpftool btf dump id <tab>". Any chance to get that in a follow-up patch?

We currently don't have a way to iterate all BTFs in a system (neither
in bpftool, nor in libbpf, AFAICT), but I can do that based on btf_id
field, dumped as part of `bpftool prog list` command. Would that work?
I'll post that as a separate patch.

>
> > +                                        _bpftool_once_attr 'format'
> > +                                    fi
> > +                                    ;;
> > +                                map|prog)
> > +                                    if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then
> > +                                        COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) )
> > +                                    fi
> > +                                    if [[ $cword > 5 ]]; then
>
> Same remark on the "if", I do not believe it is necessary?

Yep, removed.

>
> > +                                        _bpftool_once_attr 'format'
> > +                                    fi
> > +                                    ;;
> > +                                *)
> > +                                    ;;
> > +                            esac
> >                              return 0
> >                              ;;
> >                      esac
> >
>
Quentin Monnet May 24, 2019, 7:42 p.m. UTC | #3
2019-05-24 11:10 UTC-0700 ~ Andrii Nakryiko <andrii.nakryiko@gmail.com>
> On Fri, May 24, 2019 at 2:15 AM Quentin Monnet
> <quentin.monnet@netronome.com> wrote:
>>
>> 2019-05-23 13:42 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
>>> Add bash completion for new C btf dump option.
>>>
>>> Cc: Quentin Monnet <quentin.monnet@netronome.com>
>>> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>>> ---
>>>  tools/bpf/bpftool/bash-completion/bpftool | 25 +++++++++++++++++++----
>>>  1 file changed, 21 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
>>> index 50e402a5a9c8..5b65e0309d2a 100644
>>> --- a/tools/bpf/bpftool/bash-completion/bpftool
>>> +++ b/tools/bpf/bpftool/bash-completion/bpftool
>>> @@ -638,11 +638,28 @@ _bpftool()
>>>                              esac
>>>                              return 0
>>>                              ;;
>>> +                        format)
>>> +                            COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) )
>>> +                            ;;
>>>                          *)
>>> -                            if [[ $cword == 6 ]] && [[ ${words[3]} == "map" ]]; then
>>> -                                 COMPREPLY+=( $( compgen -W 'key value kv all' -- \
>>> -                                     "$cur" ) )
>>> -                            fi
>>> +                            # emit extra options
>>> +                            case ${words[3]} in
>>> +                                id|file)
>>> +                                    if [[ $cword > 4 ]]; then
>>
>> Not sure if this "if" is necessary. It seems to me that if $cword is 4
>> then we are just after "id" or "file" in the command line, in which case
>> we hit previous cases and never reach this point?
> 
> Yep, you are right, removed.
> 
>>
>> Also, reading the completion code I wonder, do we have completion for
>> BTF ids? It seems to me that we have nothing proposed to complete
>> "bpftool btf dump id <tab>". Any chance to get that in a follow-up patch?
> 
> We currently don't have a way to iterate all BTFs in a system (neither
> in bpftool, nor in libbpf, AFAICT), but I can do that based on btf_id
> field, dumped as part of `bpftool prog list` command. Would that work?
> I'll post that as a separate patch.

Yes, I suppose it would. Unless there is a plan to add a "bpftool btf
dump" soon, in which case it could wait? But otherwise parsing "bpftool
prog list --pretty" (better parse JSON output, more stable) should be fine.

Thanks!
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 50e402a5a9c8..5b65e0309d2a 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -638,11 +638,28 @@  _bpftool()
                             esac
                             return 0
                             ;;
+                        format)
+                            COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) )
+                            ;;
                         *)
-                            if [[ $cword == 6 ]] && [[ ${words[3]} == "map" ]]; then
-                                 COMPREPLY+=( $( compgen -W 'key value kv all' -- \
-                                     "$cur" ) )
-                            fi
+                            # emit extra options
+                            case ${words[3]} in
+                                id|file)
+                                    if [[ $cword > 4 ]]; then
+                                        _bpftool_once_attr 'format'
+                                    fi
+                                    ;;
+                                map|prog)
+                                    if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then
+                                        COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) )
+                                    fi
+                                    if [[ $cword > 5 ]]; then
+                                        _bpftool_once_attr 'format'
+                                    fi
+                                    ;;
+                                *)
+                                    ;;
+                            esac
                             return 0
                             ;;
                     esac