Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 12, 2026·3 min de lecture

Oclif — Open CLI Framework for Building TypeScript Command-Line Tools

A framework by Salesforce for building extensible CLI applications in TypeScript with plugins, auto-generated help, and argument parsing.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Stage only · 17/100Stage only
Surface agent
Tout agent MCP/CLI
Type
CLI Tool
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
Oclif
Commande CLI universelle
npx tokrepo install 4b049ef8-4dfd-11f1-9bc6-00163e2b0d79

Introduction

Oclif (Open CLI Framework) is a TypeScript-first framework for building command-line tools. Created by Salesforce and used to power the Heroku CLI and Salesforce CLI, it provides a structured way to define commands, flags, arguments, and plugins for CLIs of any size.

What Oclif Does

  • Scaffolds new CLI projects with a single command using the generator
  • Provides a class-based command structure with typed flags and arguments
  • Auto-generates help text, man pages, and README documentation from command metadata
  • Supports a plugin system that lets users extend your CLI with third-party packages
  • Handles command discovery, lifecycle hooks, and error reporting out of the box

Architecture Overview

Oclif organizes a CLI as a collection of command classes, each defining its flags, arguments, and run method. At startup, the framework discovers commands from the file system or installed plugin packages and builds a command tree. Flag and argument parsing uses a strict, typed approach that validates input before the command runs. Plugins are npm packages that expose additional commands and hooks, loaded dynamically at runtime.

Self-Hosting & Configuration

  • Generate a new project: npx oclif generate my-cli
  • Define commands as TypeScript classes in the src/commands/ directory
  • Configure the CLI name, version, and plugins in package.json under the oclif key
  • Distribute via npm or build standalone installers for macOS, Windows, and Linux
  • Add plugins by listing them in the oclif.plugins array or let users install them dynamically

Key Features

  • TypeScript-first with full type inference for flags, arguments, and configuration
  • Plugin architecture powering large-scale CLIs like Heroku CLI and Salesforce CLI
  • Auto-generated help output formatted for terminal with color and layout
  • Built-in testing utilities for unit and integration testing commands
  • Standalone packaging to create single-binary installers without requiring Node.js

Comparison with Similar Tools

  • Commander.js — lightweight flag parser; Oclif adds plugins, scaffolding, and auto-generated docs
  • Yargs — flexible argument parsing; Oclif provides more structure with classes and lifecycle hooks
  • Cobra (Go) — similar command framework for Go; Oclif is the TypeScript equivalent
  • Clipanion — Yarn's CLI engine; Oclif has a larger ecosystem and standalone packaging

FAQ

Q: Can I use Oclif with plain JavaScript? A: Yes, though TypeScript is recommended. The generator scaffolds TypeScript by default.

Q: How do plugins work? A: Plugins are npm packages that export Oclif commands. Users install them with my-cli plugins install plugin-name.

Q: Can I build standalone executables? A: Yes. Oclif includes a pack command that creates tarballs and platform-specific installers.

Q: What CLIs are built with Oclif? A: Heroku CLI, Salesforce CLI (sf), Shopify CLI, and Twilio CLI are all built on Oclif.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires