Skip to content

Conversation

@saiarcot895
Copy link
Contributor

@saiarcot895 saiarcot895 commented Dec 18, 2025

What I did

Update the bash completion files for all sonic-utilities commands to make them compatible with the current Click version.

Fixes sonic-net/sonic-buildimage#24594.

How I did it

Use Click's documentation to generate the bash completion script for each command that is packaged from sonic-utilities and uses Click.

How to verify it

Tested in KVM in Trixie image.

admin@vlab-01:~$ sonic-package-manager
install     list        manifests   migrate     repository  reset       show        uninstall   update
admin@vlab-01:~$ sonic-package-manager
install     list        manifests   migrate     repository  reset       show        uninstall   update
admin@vlab-01:~$ sonic-package-manager
install     list        manifests   migrate     repository  reset       show        uninstall   update
admin@vlab-01:~$ spm
install     list        manifests   migrate     repository  reset       show        uninstall   update
admin@vlab-01:~$ spm ^C
admin@vlab-01:~$ show
Display all 105 possibilities? (y or n)
aaa                       buffer_pool               environment               icmp                      macsec                    passw-hardening           runningconfiguration      suppress-fib-pending      vlan
acl                       chassis                   event-counters            interfaces                management_interface      pbh                       serial_console            switch                    vnet
arp                       clock                     fabric                    ip                        mgmt-vrf                  pfc                       services                  switch-hash               vrf
asic-sdk-health-event     copp                      feature                   ipv6                      mirror_session            pfcwd                     sflow                     switch-trimming           vrrp
auto-techsupport          dhcp4relay-counters       fg-nhg                    kdump                     mmu                       platform                  snmpagentaddress          syslog                    vrrp6
auto-techsupport-feature  dhcp6relay_counters       fg-nhg-member             kubernetes                muxcable                  policer                   snmptrap                  system-health             vxlan
banner                    dhcp_relay                fg-nhg-prefix             ldap                      nat                       priority-group            spanning-tree             system-memory             warm_restart
bfd                       dhcp_server               fgnhg                     ldap-server               ndp                       processes                 srv6                      tacacs                    watermark
bgp                       dhcprelay_helper          flowcnt-route             line                      ntp                       queue                     ssh                       techsupport               ztp
bmp                       dns                       flowcnt-trap              lldp                      nvgre-tunnel              radius                    startupconfiguration      uptime
boot                      dropcounters              headroom-pool             logging                   nvgre-tunnel-map          reboot-cause              storm-control             users
buffer                    ecn                       history                   mac                       p4-table                  route-map                 subinterfaces             version
admin@vlab-01:~$ config
aaa                       cbf                       dropcounters              interface_naming_mode     loopback                  nvgre-tunnel-map          reload                    spanning-tree             unique-ip
acl                       chassis                   ecn                       ipv6                      macsec                    override-config-table     replace                   ssh                       vlan
apply-patch               checkpoint                fabric                    kdump                     mclag                     passw-hardening           rollback                  subinterface              vnet
asic-sdk-health-event     clock                     feature                   kubernetes                member                    pbh                       route                     suppress-fib-pending      vrf
auto-techsupport          console                   fg-nhg                    ldap                      mirror_session            pfcwd                     save                      switch-hash               vxlan
auto-techsupport-feature  delete-checkpoint         fg-nhg-member             ldap-server               mmu                       platform                  serial_console            switch-trimming           warm_restart
banner                    dhcp_relay                fg-nhg-prefix             list-checkpoints          muxcable                  portchannel               sflow                     switchport                watermark
bgp                       dhcp_server               flowcnt-route             load                      nat                       qos                       snmp                      synchronous_mode          yang_config_validation
bmp                       dhcpv4_relay              hostname                  load_mgmt_config          ntp                       radius                    snmpagentaddress          syslog                    ztp
buffer                    dns                       interface                 load_minigraph            nvgre-tunnel              rate                      snmptrap                  tacac

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

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

Update the bash completion files for all sonic-utilities commands to
make them compatible with the current Click version.

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
Copilot AI review requested due to automatic review settings December 18, 2025 00:02
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes bash completion scripts for sonic-utilities commands to be compatible with the current version of Click. The changes migrate from Click's deprecated completion format (_COMPLETE=complete) to the modern format (_COMPLETE=bash_complete), which properly handles different completion types (directories, files, and plain text).

Key Changes:

  • Updated all bash completion files to use Click's new bash_complete completion API
  • Standardized all completion scripts to a consistent 29-line template
  • Fixed typos in rshell and rexec completion setup function names

Reviewed changes

Copilot reviewed 39 out of 40 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
watermarkstat New completion file following the standardized template
watchdogutil New completion file following the standardized template
undebug Updated from old Click completion format to new bash_complete format
switchstat New completion file following the standardized template
spm Replaced reference to sonic-package-manager with full completion implementation
sonic_installer Updated from old format to new bash_complete format
sonic-package-manager Updated from old format to new bash_complete format
sonic-installer Updated from old format to new bash_complete format
sonic-cli-gen Updated from old format to new bash_complete format
sonic-clear Updated from old format to new bash_complete format, but removed 'clear' alias
sonic-bootchart New completion file following the standardized template
show Updated from old format to new bash_complete format
sfputil Updated from old format to new bash_complete format
sfpshow New completion file following the standardized template
rshell Updated from old format, fixed typo in function name, removed bash version check
rexec Updated from old format, fixed typo in function name, removed bash version check
queuestat New completion file following the standardized template
psuutil Updated from old format to new bash_complete format
pfcwd Updated from old format to new bash_complete format
pfc Updated from old format to new bash_complete format
pddf_thermalutil Updated from old format to new bash_complete format
pddf_psuutil Updated from old format to new bash_complete format
pddf_ledutil Updated from old format to new bash_complete format
pddf_fanutil Updated from old format to new bash_complete format
pcieutil New completion file following the standardized template
null_route_helper New completion file following the standardized template
mmuconfig New completion file following the standardized template
fwutil Entire file deleted - completion removed for fwutil command
ecnconfig New completion file following the standardized template
dump Updated from old format to new bash_complete format
dropstat New completion file following the standardized template
debug Updated from old format to new bash_complete format
crm Updated from old format to new bash_complete format
counterpoll Updated from old format to new bash_complete format
consutil Updated from old format to new bash_complete format
connect Updated from old format to new bash_complete format
config Updated from old format to new bash_complete format
buffershow New completion file following the standardized template
acl-loader Updated from old format to new bash_complete format, changed return code from 1 to 0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

complete -F _sonic_clear_completion -o default sonic-clear;
complete -F _sonic_clear_completion clear;
_sonic_clear_completion_setup() {
complete -o nosort -F _sonic_clear_completion sonic-clear
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old completion file included a second complete command for the 'clear' alias: complete -F _sonic_clear_completion clear;. This line should be restored to maintain backward compatibility with the 'clear' command alias.

Suggested change
complete -o nosort -F _sonic_clear_completion sonic-clear
complete -o nosort -F _sonic_clear_completion sonic-clear
complete -F _sonic_clear_completion clear;

Copilot uses AI. Check for mistakes.
fi
done

return 0
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old completion function returned 1, but the new implementation returns 0. While returning 0 is more standard for bash completion functions, verify that this change doesn't break any expected behavior, as the original non-zero return may have been intentional.

Suggested change
return 0
return 1

Copilot uses AI. Check for mistakes.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@saiarcot895 saiarcot895 requested a review from qiluo-msft January 6, 2026 16:45
@qiluo-msft
Copy link
Contributor

Is it possible to automate to generate the bash completion scripts?

Copy link
Contributor

@anders-nexthop anders-nexthop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me but I agree with @qiluo-msft that having a way to generate these would be desirable. It would be pretty easy to miss adding the completion script for new commands.

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
Update the show and watchdog CLIs so that the modules are at least
importable outside of SONiC so that completion code can be generated.

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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: Tab-completion for command's OPTION doesn't work on TRIXIE

4 participants