- Notifications
You must be signed in to change notification settings - Fork333
CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.
License
oclif/oclif
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- 🗒 Description
- 🚀 Getting Started Tutorial
- ✨ Features
- 📌 Requirements
- 🌈 CLI Types
- 🏗 Usage
- 📚 Examples
- 🔨 Commands
- 🏭 Related Repositories
- 🦔 Learn More
- 📣 Feedback
This is a framework for building CLIs in Node.js. This framework was built out of theHeroku CLI but generalized to build any custom CLI. It's designed both for single-file CLIs with a few flag options, or for very complex CLIs that have subcommands (like git or heroku).
See the docs for more information.
TheGetting Started tutorial is a step-by-step guide to introduce you to oclif. If you have not developed anything in a command line before, this tutorial is a great place to get started.
- Flag/Argument parsing - No CLI framework would be complete without a flag parser. We've built a custom one from years of experimentation that we feel consistently handles user input flexible enough for the user to be able to use the CLI in ways they expect, but without compromising strictness guarantees to the developer.
- Super Speed - The overhead for running an oclif CLI command is almost nothing.It requires very few dependencies (only 35 dependencies in a minimal setup—including all transitive dependencies). Also, only the command to be executed will be required with node. So large CLIs with many commands will load equally as fast as a small one with a single command.
- CLI Generator - Run a single command to scaffold out a fully functional CLI and get started quickly. SeeUsage below.
- Testing Helpers - We've put a lot of work into making commands easier to test and mock out stdout/stderr. The generator will automatically createscaffolded tests.
- Auto-documentation - By default you can pass
--help
to the CLI to get help such as flag options and argument information. This information is also automatically placed in the README whenever the npm package of the CLI is published. See themulti-command CLI example - Plugins - Usingplugins, users of the CLI can extend it with new functionality, a CLI can be split into modular components, and functionality can be shared amongst multiple CLIs. SeeBuilding your own plugin.
- Hooks - Use lifecycle hooks to run functionality any time a CLI starts, or on custom triggers. Use this whenever custom functionality needs to be shared between various components of the CLI.
- TypeScript (or not) - Everything in the core of oclif is written in TypeScript and the generator can build fully configured TypeScript CLIs or plain JavaScript CLIs. By virtue of static properties in TypeScript the syntax is a bit cleaner in TypeScript—but everything will work no matter which language you choose. If you use plugins support, the CLI will automatically use
ts-node
to run the plugins enabling you to use TypeScript with minimal-to-no boilerplate needed for any oclif CLI. - Auto-updating Installers - oclif can package your CLI intodifferent installers that will not require the user to already have node installed on the machine. These can be made auto-updatable by usingplugin-update.
- Everything is Customizable - Pretty much anything can be swapped out and replaced inside oclif if needed—including the arg/flag parser.
- Autocomplete - Automatically include autocomplete for your CLI. This includes not only command names and flag names, but flag values as well. For example, it's possible to configure the Heroku CLI to have completions for Heroku app names:
$ heroku info --app=<tab><tab> # will complete with all the Heroku apps a user has in their account
Currently, Node 8+ is supported. We support theLTS versions of Node. You can add thenode package to your CLI to ensure users are running a specific version of Node.
With oclif you can create 2 different CLI types, single and multi.
Single CLIs are likels
orcat
. They can accept arguments and flags. Single CLIs canoptionally be a single file.
Multi CLIs are likegit
orheroku
. They have subcommands that are themselves single CLIs. In thepackage.json
there is a fieldoclif.commands
that points to a directory. This directory contains all the subcommands for the CLI. For example, if you had a CLI calledmycli
with the commandsmycli create
andmycli destroy
, you would have a project like the following:
package.jsonsrc/└── commands/ ├── create.ts └── destroy.ts
Multi-command CLIs may also includeplugins.
Creating a single-command CLI:
$npx oclif single mynewcli? npm package name (mynewcli): mynewcli$cd mynewcli$./bin/runhello world from ./src/index.js!
Creating a multi-command CLI:
$npx oclif multi mynewcli? npm package name (mynewcli): mynewcli$cd mynewcli$./bin/run --versionmynewcli/0.0.0 darwin-x64 node-v9.5.0$./bin/run --helpUSAGE $ mynewcli [COMMAND]COMMANDS hello help display help for mynewcli$./bin/run hellohello world from ./src/hello.js!
- TypeScript
- JavaScript
oclif command NAME
oclif help [COMMAND]
oclif hook NAME
oclif multi [PATH]
oclif plugin [PATH]
oclif single [PATH]
add a command to an existing CLI or plugin
USAGE $ oclif command NAMEARGUMENTS NAME name of commandOPTIONS --defaults use defaults for every setting --force overwrite existing files
See code:src/commands/command.ts
display help for oclif
USAGE $ oclif help [COMMAND]ARGUMENTS COMMAND command to show help forOPTIONS --all see all commands in CLI
See code:@oclif/plugin-help
add a hook to an existing CLI or plugin
USAGE $ oclif hook NAMEARGUMENTS NAME name of hook (snake_case)OPTIONS --defaults use defaults for every setting --event=event [default: init] event to run hook on --force overwrite existing files
See code:src/commands/hook.ts
generate a new multi-command CLI
USAGE $ oclif multi [PATH]ARGUMENTS PATH path to project, defaults to current directoryOPTIONS --defaults use defaults for every setting --force overwrite existing files --options=options (yarn|typescript|eslint|mocha)
See code:src/commands/multi.ts
create a new CLI plugin
USAGE $ oclif plugin [PATH]ARGUMENTS PATH path to project, defaults to current directoryOPTIONS --defaults use defaults for every setting --force overwrite existing files --options=options (yarn|typescript|eslint|mocha)
See code:src/commands/plugin.ts
generate a new single-command CLI
USAGE $ oclif single [PATH]ARGUMENTS PATH path to project, defaults to current directoryOPTIONS --defaults use defaults for every setting --force overwrite existing files --options=options (yarn|typescript|eslint|mocha)
See code:src/commands/single.ts
- @oclif/command - Base command for oclif. This can be used directly without the generator.
- @oclif/config - Most of the core setup for oclif lives here.
- @oclif/errors - Renders and logs errors from commands.
- @oclif/cli-ux - Library for common CLI UI utilities.
- @oclif/test - Test helper for oclif.
If you have any suggestions or want to let us know what you think of oclif, send us a message atheroku-cli@salesforce.com
About
CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.