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.
-
rctlinstalled:
Create and install a plugin
1
Generate the plugin
Run the oclif generator and answer its prompts. This example names the plugin The generator creates a TypeScript project with a sample
mycommand:hello command:2
Write the command
Edit To manage Routr resources from a command, add
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
@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: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
rctlcommand replaces it. Pick topic names that don’t clash withagents,domains,peers,trunks,numbers,credentials, oracl. - Commands use spaces.
rctlseparates topics with a space (rctl plugins link), so yourhello/world.tscommand runs asrctl hello world.
Related
rctl reference
Every built-in command and flag.
Manage resources with the SDK
Call the API Server from your plugin.