Repository navigation
[Nexthop][fboss2-dev] bash completion for leaf attribute tokens - #1689
Open
benoit-nexthop wants to merge 1 commit into
Open
benoit-nexthop wants to merge 1 commit into
benoit-nexthop wants to merge 1 commit into
Conversation
benoit-nexthop
force-pushed
the
fboss2-bash-completion
branch
from
September 29, 2026 21:17
4db1832 to
91a3695
Compare
benoit-nexthop
force-pushed
the
fboss2-bash-completion
branch
from
October 7, 2026 22:23
91a3695 to
9ad4aad
Compare
Contributor
Author
|
/autorebase |
rabbit-nexthop
force-pushed
the
fboss2-bash-completion
branch
from
October 11, 2026 20:45
9ad4aad to
8ea0aac
Compare
rabbit-nexthop
force-pushed
the
fboss2-bash-completion
branch
from
October 25, 2026 21:10
8ea0aac to
60e0a11
Compare
Summary:
FBOSS tab completion (`fboss2 __completion`) only walks the CLI11
sub-command tree, so it stops at `config arp` and cannot offer `timeout`,
`max-probes`, ...: the config/delete commands keep the last level of
tokens in a list inside one handler rather than as one .cpp/.h per leaf,
to avoid code bloat.
This gives commands a uniform way to complete those tokens:
- A Traits may declare
`static std::vector<std::string> completeArgs(const std::vector<std::string>& typed)`
returning the tokens that may follow the positionals typed so far.
`argRegistrar<Traits>` (now a struct carrying both addCliArg and the
optional completer) picks it up, and CmdSubcommands remembers it per
CLI11 command. No command-tree entries change; a Traits without
completeArgs simply gets no leaf completion.
- utils/ArgCompletion.h holds the three grammars that recur across the
tree so nearly every command is a one-liner: completeAttrGrammar for
`[<object>...] <attr> <value> ...` (per-attr enum values, valueless
attrs, multi-word attrs such as `timers hold-time`, used attrs not
offered again), completeAttrList for the delete-side `<attr> [<attr>...]`
and completePositions for fixed positional grammars.
- CmdCompletion.cpp walks the CLI11 tree along the typed words (skipping
options and their values), then offers sub-commands, the completer's
candidates, or option names when the word starts with '-'. Sub-commands
are not offered while an attribute's value is being completed, and
nothing is offered while an option's value is under the cursor.
- completeArgs added to every config/delete command with a static
vocabulary (arp, interface and its sub-commands, load-balancing, copp,
traffic-policy, acl, tunnel, qos, bgp, static routes, l2, ptp, vlan
tagging, dhcp, srv6). Free-form-only commands (names, ids, prefixes)
opt out by not declaring it.
- The bash script now passes the word under the cursor, completes
fboss2-dev as well as fboss2, and asks the binary being completed.
package.py ships it under share/bash-completion and setup_fboss_env
sources it in interactive shells (before its idempotency guard, since
completion specs are not inherited by child shells; bash-completion's
lazy loader would not look under /opt/fboss anyway). The image now also
bundles the bash-completion package.
Test Plan:
Unit tests: ArgCompletionTest covers the three grammars; CmdCompletionTest
completes against the real fboss2-dev command trees (it lives in cmd_test,
which links the config command tree).
fboss2_framework_test
[ PASSED ] 42 tests.
fboss2_cmd_test --gtest_filter='CmdCompletionTest.*:CmdListConfigTest.*'
[ PASSED ] 9 tests.
fboss2_cmd_config_test
[ PASSED ] 1162 tests.
On an NH-4010-F test switch, installed the new fboss2-dev, the completion
script under /opt/fboss/share/bash-completion/completions/fboss2 and the
new setup_fboss_env, then checked that a login shell registers the
completions:
$ bash -lic 'complete -p fboss2-dev fboss2'
complete -F _fboss2_complete fboss2-dev
complete -F _fboss2_complete fboss2
and pressed TAB in an interactive shell for a range of command lines.
Sample outputs, captured from an interactive bash login shell on the
switch (80 columns, `<TAB>` marks where TAB was pressed). Leaf attributes,
attribute values, two-word BGP attributes and options all complete; a
single match is filled in directly:
$ fboss2-dev config arp <TAB>
age-interval max-probes stale-interval timeout
$ fboss2-dev config arp ti<TAB>
$ fboss2-dev config arp timeout
$ fboss2-dev config arp timeout 30 <TAB>
age-interval max-probes stale-interval
$ fboss2-dev config interface eth1/1/1 <TAB>
description lookup-class
dhcp loopback-mode
flow-control-rx mtu
flow-control-tx name
ip-address no-shutdown
ipv6 pfc-config
ipv6-address profile
lldp-expected-chassis queue-config
lldp-expected-port-desc sflow
lldp-expected-system-desc shutdown
lldp-expected-system-name switchport
lldp-expected-ttl type
lldp-expected-value
$ fboss2-dev config interface eth1/1/1 loopback-mode <TAB>
MAC NIF none PHY
$ fboss2-dev config interface eth1/1/1 sflow sample-dest <TAB>
cpu mirror
$ fboss2-dev config copp reason <TAB>
arp eapol mpls-unknown-label
arp-response host-miss ndp
bgp l3-dest-miss port-mtu-error
bgpv6 l3-mtu-error samplepacket
bpdu l3-slow-path ttl-0
cpu-is-nhop lacp ttl-1
dhcp lldp unmatched
dhcpv6 mpls-ttl-1
$ fboss2-dev config copp queue 1 scheduling <TAB>
DEFICIT_ROUND_ROBIN SP WRR
DRR STRICT_PRIORITY
INTERNAL WEIGHTED_ROUND_ROBIN
$ fboss2-dev config protocol bgp neighbor 1.2.3.4 timers <TAB>
hold-time out-delay
keepalive withdraw-unprog-delay
$ fboss2-dev show interface --<TAB>
--agent-port --detail --fsdb-port --qsfp-port
--aggregate --file --help
--aggregate-hosts --filter --host
--color --fmt --loglevel
benoit-nexthop
force-pushed
the
fboss2-bash-completion
branch
from
November 1, 2026 10:28
60e0a11 to
f18f8b9
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FBOSS tab completion (
fboss2 __completion) only walks the CLI11sub-command tree, so it stops at
config arpand cannot offertimeout,max-probes, ...: the config/delete commands keep the last level oftokens in a list inside one handler rather than as one .cpp/.h per leaf,
to avoid code bloat.
This gives commands a uniform way to complete those tokens:
static std::vector<std::string> completeArgs(const std::vector<std::string>& typed)returning the tokens that may follow the positionals typed so far.
argRegistrar<Traits>(now a struct carrying both addCliArg and theoptional completer) picks it up, and CmdSubcommands remembers it per
CLI11 command. No command-tree entries change; a Traits without
completeArgs simply gets no leaf completion.
tree so nearly every command is a one-liner: completeAttrGrammar for
[<object>...] <attr> <value> ...(per-attr enum values, valuelessattrs, multi-word attrs such as
timers hold-time, used attrs notoffered again), completeAttrList for the delete-side
<attr> [<attr>...]and completePositions for fixed positional grammars.
options and their values), then offers sub-commands, the completer's
candidates, or option names when the word starts with '-'. Sub-commands
are not offered while an attribute's value is being completed, and
nothing is offered while an option's value is under the cursor.
vocabulary (arp, interface and its sub-commands, load-balancing, copp,
traffic-policy, acl, tunnel, qos, bgp, static routes, l2, ptp, vlan
tagging, dhcp, srv6). Free-form-only commands (names, ids, prefixes)
opt out by not declaring it.
fboss2-dev as well as fboss2, and asks the binary being completed.
package.py ships it under share/bash-completion and setup_fboss_env
sources it in interactive shells (before its idempotency guard, since
completion specs are not inherited by child shells; bash-completion's
lazy loader would not look under /opt/fboss anyway). The image now also
bundles the bash-completion package.
Test Plan
Unit tests: ArgCompletionTest covers the three grammars; CmdCompletionTest
completes against the real fboss2-dev command trees (it lives in cmd_test,
which links the config command tree).
On an NH-4010-F test switch, installed the new fboss2-dev, the completion
script under /opt/fboss/share/bash-completion/completions/fboss2 and the
new setup_fboss_env, then checked that a login shell registers the
completions:
and pressed TAB in an interactive shell for a range of command lines.
Sample outputs
Captured from an interactive bash login shell on the
switch (80 columns,
<TAB>marks where TAB was pressed). Leaf attributes,attribute values, two-word BGP attributes and options all complete; a
single match is filled in directly: