Used to create a CLI interface to any plugable-express server providing integrated endpoint discovery, tab completion, interactive mode, and help.
This library provides a framework for building command-line interfaces that seamlessly communicate with plugable-express servers. When you create a CLI using this framework, it automatically:
- Discovers server endpoints through the server's API specification
- Provides tab completion for all available commands and parameters
- Auto-starts the server if it's not already running
- Handles interactive Q&A flows for complex operations
- Formats responses appropriately for terminal display
- Supports interactive mode with a REPL-like interface for continuous interaction
The CLI dynamically adapts to the server's capabilities, meaning that as new endpoints are added to the server, they immediately become available through the CLI without any CLI code changes.
For example, sdlcpilot-cli uses this framework to create a CLI interface for the sdlcforge-server, providing commands for software development lifecycle management. The CLI automatically discovers all available commands from the server and provides a rich, interactive experience.
npm install @liquid-labs/plugable-express-cliCreate a CLI executable file that configures and starts the CLI interface. Here's an example from sdlcpilot-cli:
import { readFileSync } from 'node:fs'
import * as fsPath from 'node:path'
import { startCLI } from '@liquid-labs/plugable-express-cli'
// Function to get version from package.json
const getVersion = () => {
const packagePath = fsPath.resolve(__dirname, '..', 'package.json')
const pkgJSON = JSON.parse(readFileSync(packagePath, { encoding: 'utf8' }))
return pkgJSON.version
}
// Configure CLI settings
const cliSettings = {
cliName: 'sdlc', // Your CLI command name
getVersion, // Version function
port: 8080, // Server port
serverAPIPath: '/path/to/api.json', // API specification path
serverExec: 'sdlcforge-server', // Server executable command
serverHome: '/path/to/server/home', // Server home directory
serverPackage: '@sdlcforge/core-server', // NPM package name of server
serverVersion: 'latest', // Server version to install
// Optional settings
protocol: 'http', // Default: 'http'
server: '127.0.0.1', // Default: '127.0.0.1'
defaultRegistries: ['https://registry.npmjs.org'], // NPM registries
localServerDevPaths: ['/path/to/local/server'] // For development
}
// Start the CLI
const startMyCLI = async() => await startCLI(cliSettings)
export { startMyCLI }cliName: The command name users will type to run your CLIport: Port number where the server runsserverPackage: NPM package name of the plugable-express server
getVersion: Function returning the CLI versionprotocol: HTTP protocol (default: 'http')server: Server hostname (default: '127.0.0.1')serverAPIPath: Path to the server's API specification fileserverExec: Command to execute the serverserverHome: Server's home directory for data storageserverVersion: Version of the server package to usedefaultRegistries: NPM registries for server installationlocalServerDevPaths: Local paths for development servers
When users first run your CLI, they'll need to run the setup command:
your-cli --setupThis will:
- Create the CLI home directory
- Configure CLI settings
- Install the server package
- Set up tab completion for bash/zsh
- Initialize server settings
Once set up, users can:
Run commands directly:
your-cli users list -- format=yamlEnter interactive mode:
your-cli
> users list -- format=yaml
> . # ExitUse tab completion:
your-cli [TAB] # Shows available commandsThe CLI automatically handles HTTP methods, path construction, and parameter passing based on the server's API specification.