Skip to content

[Nexthop] Implement distributed command registration system#1016

Open
manoharan-nexthop wants to merge 2 commits intofacebook:mainfrom
nexthop-ai:manoharan.cmd-refactor-1
Open

[Nexthop] Implement distributed command registration system#1016
manoharan-nexthop wants to merge 2 commits intofacebook:mainfrom
nexthop-ai:manoharan.cmd-refactor-1

Conversation

@manoharan-nexthop
Copy link
Contributor

Summary

Currently the CommandTree is statically built with all the commands and their actions defined in a single file CmdListConfig.cpp / CmdList.cpp. This makes it difficult to maintain over time and with all the commands included in a single file, makes the compilation slow.

Proposed mechanism:
Each CLI will do the registration of the CLI statically from within its definition file. As an Example,

   namespace {
   facebook::fboss::CommandDef<facebook::fboss::CmdConfigVlanStaticMac>
       registerConfigVlanStaticMac(
           "config vlan static-mac",
           "Configure VLAN static MAC");
   } // namespace

When the above is done, the CommandDef class invokes CommandRegistry::registerCommand() to add the command to a vector at the start of the CLI process.

And when the CLI initialization is done invoking kCommandTree(), it invokes CommandRegistry::buildTree() to create the sorted tree by splitting the command string and creating nodes for them.

Since the commands are registered (added to vector at random order), config vlan static-mac could come before config vlan, the buildTree takes care of handling them gracefully based on the handler registration information for each CLI.

There are 3 registration types that are introduced:

Type Use Case Handlers
CommandDef Commands with handlers (most commands) Auto-inferred from CmdType
CommandDefNoHandler Leaf commands with no children and no handler None
AttributeDef Simple attributes handled by parent Only argTypeHandler

NOTE: Parent commands (commands with children) must use CommandDef (as it is required to handle the depth counter in argument parsing).

Test Plan

  1. All the Unit tests passes
  2. Ran the CLI end to end tests and they pass.

…individual files

Move explicit template instantiations from the monolithic
CmdHandlerImplConfig.cpp file to individual command .cpp files.
This is the first step in refactoring the CLI command registration
system to avoid creating a monolithic include file.
Currently the `CommandTree` is statically built with all the commands and their actions defined in a single file `CmdListConfig.cpp` / `CmdList.cpp`. This makes it difficult to maintain over time and with all the commands included in a single file, makes the compilation slow.

Proposed mechanism:
Each CLI will do the registration of the CLI statically from within its definition file. As an Example,
```
   namespace {
   facebook::fboss::CommandDef<facebook::fboss::CmdConfigVlanStaticMac>
       registerConfigVlanStaticMac(
           "config vlan static-mac",
           "Configure VLAN static MAC");
   } // namespace

```
When the above is done, the `CommandDef` class invokes `CommandRegistry::registerCommand()` to add the command to a `vector` at the start of the CLI process.

And when the CLI initialization is done invoking `kCommandTree()`, it invokes `CommandRegistry::buildTree()` to create the sorted tree by splitting the command string and creating nodes for them.

Since the commands are registered (added to `vector` at random order), `config vlan static-mac` could come before `config vlan`, the `buildTree` takes care of handling them gracefully based on the handler registration information for each CLI.

There are 3 registration types that are introduced:
   | Type | Use Case | Handlers |
   |------|----------|----------|
   | CommandDef<CmdType> | Commands with handlers (most commands) | Auto-inferred from CmdType |
   | CommandDefNoHandler | Leaf commands with no children and no handler | None |
   | AttributeDef | Simple attributes handled by parent | Only argTypeHandler |

NOTE: Parent commands (commands with children) must use CommandDef<CmdType> (as it is required to handle the depth counter in argument parsing).

1. All the Unit tests passes
2. Ran the CLI end to end tests and they pass.
@manoharan-nexthop manoharan-nexthop requested review from a team as code owners March 18, 2026 12:53
@meta-cla meta-cla bot added the CLA Signed label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant