← Back to archive

Repo of the Day

oclif/core

Published: Feb 23, 2025

Open repository ↗

Node.js Open CLI Framework. Built by Salesforce.

Summary

oclif/core is a Node.js framework for building command-line interfaces, originally generalized from the Salesforce CLI. It supports both simple single-file CLIs and complex multi-command tools, is written in TypeScript, and is published as the npm package @oclif/core under an MIT license.

What it is useful for

oclif/core is useful when an engineer needs to build a Node.js CLI and wants a structured approach to flag and argument parsing, help text generation, and command organization. According to the README, it fits both single-command CLIs like cat or ls and complex CLIs with subcommands like git or heroku. Documented features include a flag and argument parser, lifecycle hooks, a plugin system for extending or modularizing a CLI, autocomplete for command, flag, and flag-value names, automatic --help output, and README documentation generation when the CLI's npm package is published. The README also notes the generator scaffolds a fully configured TypeScript project, and that TypeScript-based plugins are run with ts-node automatically. For distribution, oclif can produce installers that do not require users to have Node installed, and those installers can be made auto-updatable via the separate plugin-update package.

How engineers can use it

The README recommends generating a CLI with the oclif CLI tool, which creates an npm package that depends on @oclif/core, then following the Getting Started tutorial on the oclif.io docs site. For ad hoc scripts, @oclif/core can be used standalone: the README provides a complete TypeScript example defining a Command subclass with Flags and this.parse, then calling LS.run(...), runnable with ts-node. The Parser class can also be imported separately for parsing only, as shown in a second example that imports Args, Flags, and Parser and calls Parser.parse(process.argv.slice(2), ...). A documented limitation is that when Parser is used outside an oclif project, the built-in help and version flags are not available. Engineers should use Node 18 or newer, since earlier versions are not supported, and consult the v3, v2, and pre-core migration guides included in the repository when upgrading from older releases.