Skip to main content
Add your own commands to rctl by writing an oclif plugin and installing it into the CLI. rctl is built with oclif and ships with @oclif/plugin-plugins, so it can load third-party plugins at runtime. A plugin is an npm package of oclif commands. Once installed, its commands appear next to the built-in ones, and you can use the SDK inside them to talk to the API Server.

Prerequisites

  • Node.js and npm.
  • rctl installed:

Create and install a plugin

1

Generate the plugin

Run the oclif generator and answer its prompts. This example names the plugin mycommand:
The generator creates a TypeScript project with a sample hello command:
2

Write the command

Edit src/commands/hello/index.ts. Each command is a class with a description, flags, arguments, and a run() method. The generated command takes a person argument and a required --from flag:
src/commands/hello/index.ts
To manage Routr resources from a command, add @routr/sdk to the plugin and call it from run(). See Manage resources with the SDK.
3

Link it for development

From the plugin folder, link it into rctl. Linking points the CLI at your working copy, so rebuilds show up without reinstalling:
4

Run your command

Check that rctl lists the plugin and runs the command:
rctl hello world --from oclif prints hello world from oclif!.

Install a published plugin

Publish the plugin to npm like any package. Users then install it by name, or from a Git URL:
Remove a plugin with rctl plugins uninstall mycommand, and upgrade installed plugins with rctl plugins update.

Pitfalls

  • Name collisions override built-ins. A user-installed plugin that defines a command with the same name as a core rctl command replaces it. Pick topic names that don’t clash with agents, domains, peers, trunks, numbers, credentials, or acl.
  • Commands use spaces. rctl separates topics with a space (rctl plugins link), so your hello/world.ts command runs as rctl hello world.

rctl reference

Every built-in command and flag.

Manage resources with the SDK

Call the API Server from your plugin.