Skip to content

bash completion: generate Click 8-compatible scripts with type,value parsing#4330

Closed
anamehra wants to merge 3 commits intosonic-net:masterfrom
anamehra:anamehra/bash_completion
Closed

bash completion: generate Click 8-compatible scripts with type,value parsing#4330
anamehra wants to merge 3 commits intosonic-net:masterfrom
anamehra:anamehra/bash_completion

Conversation

@anamehra
Copy link
Contributor

@anamehra anamehra commented Mar 4, 2026

Fixes: sonic-net/sonic-buildimage#25882

Use a fixed template instead of Click's source() so generated scripts invoke with bash_complete, redirect stderr, and parse type,value lines to populate COMPREPLY with values only.

What I did

SONiC routers click tab auto completion does not work in master and 202511 images

How I did it

Shell completion (Click 8.x)
https://click.palletsprojects.com/en/8.0.x/shell-completion/
There’s no section titled “bash_complete”. It’s defined by the generic rule for adding a new shell:

  • In “Adding Support for a Shell” the doc says the script “must invoke your program with the environment variable _{FOO_BAR}_COMPLETE set to {shell}_complete”.
  • For the built‑in shell bash, that becomes bash_complete (i.e. {shell}_complete with shell=bash).
  • So:
    bash_source → “output the completion script to source” (run once, user evals/sources it).
    bash_complete → “run in completion mode and output the current completions” (run on each Tab with COMP_WORDS/COMP_CWORD set).

How to verify it

On router do
show
show platform

Previous command output (if the output of a command-line utility has changed)

show platf<tab> does not auto complete
show platform <tab> does not show right options
root@sfd-lc1:/home/admin# show platform <press tab>.
./                         ../                        .bash_history              .bash_logout               .bashrc                    .profile                   .sudo_as_admin_successful 

New command output (if the output of a command-line utility has changed)

root@sfd-lc0:/home/admin# show platform  <tab>
bmc          eth-switch   fan          idprom       leakage      obfl         phy          rdma-config  ssdhealth    syseeprom    versions     
current      fabric       firmware     inventory    npu          pcieinfo     psustatus    security     summary      temperature  voltage      

…parsing

Use a fixed template instead of Click's source() so generated scripts
invoke with bash_complete, redirect stderr, and parse type,value lines
to populate COMPREPLY with values only.

Signed-off-by: anamehra <anamehra@cisco.com>
@anamehra anamehra marked this pull request as draft March 4, 2026 17:20
Signed-off-by: anamehra <anamehra@cisco.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: anamehra <anamehra@cisco.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@anamehra anamehra closed this Mar 4, 2026
@anamehra anamehra deleted the anamehra/bash_completion branch March 4, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: bash show and config command auto completion does not work

2 participants