⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Add weak custom CLI hook to extend CommonCLI without forking core commands#1534

Open
piotrmalek wants to merge 2 commits intomeshcore-dev:devfrom
piotrmalek:feature/custom-cli-hook
Open

Add weak custom CLI hook to extend CommonCLI without forking core commands#1534
piotrmalek wants to merge 2 commits intomeshcore-dev:devfrom
piotrmalek:feature/custom-cli-hook

Conversation

@piotrmalek
Copy link

Summary

This PR adds an optional, weakly-linked hook to CommonCLI::handleCommand():

  • extern "C" bool meshcore_custom_cli(uint32_t sender_ts, const char* cmd, char* reply)
  • If the hook returns true, the command is considered handled and the standard CLI processing is skipped.
  • Default implementation returns false, so existing behavior is unchanged.

Motivation

Board / variant-specific builds sometimes need to add a few extra CLI commands without modifying upstream CLI code paths each time.
A weak symbol hook allows vendors and custom forks to ship additional commands as a separate translation unit, while keeping the upstream CLI intact.

Backward compatibility

  • No existing commands are modified.
  • If no custom implementation is provided, the weak default returns false and the standard CLI behaves exactly as before.

Example usage

Create e.g. customCli.cpp in your board/variant build and provide your own implementation:

#include <cstring>
#include <cstdio>
#include <cstdlib>

extern "C" bool meshcore_custom_cli(uint32_t sender_ts, const char* cmd, char* reply) {
  (void)sender_ts;

  if (strcmp(cmd, "pingx") == 0) {
    std::snprintf(reply, 64, "PONGx!");
    return true;
  }

  return false; // let it handle the standard CLI
}

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.

1 participant