UNPKG

11.1 kBMarkdownView Raw
1
2<img src="https://user-images.githubusercontent.com/449385/38243295-e0a47d58-372e-11e8-9bc0-8c02a6f4d2ac.png" width="260" height="73">
3
4
5oclif: Node.JS Open CLI Framework
6=================================
7
8[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/oclif)
9[![Version](https://img.shields.io/npm/v/oclif.svg)](https://npmjs.org/package/oclif)
10[![CircleCI](https://circleci.com/gh/oclif/oclif/tree/master.svg?style=shield)](https://circleci.com/gh/oclif/oclif/tree/master)
11[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/oclif?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/oclif/branch/master)
12[![Downloads/week](https://img.shields.io/npm/dw/@oclif/command.svg)](https://npmjs.org/package/@oclif/command)
13[![License](https://img.shields.io/npm/l/oclif.svg)](https://github.com/oclif/oclif/blob/master/package.json)
14
15<!-- toc -->
16* [🗒 Description](#-description)
17* [🚀 Getting Started Tutorial](#-getting-started-tutorial)
18* [✨ Features](#-features)
19* [📌 Requirements](#-requirements)
20* [🌈 CLI Types](#-cli-types)
21* [🏗 Usage](#-usage)
22* [📚 Examples](#-examples)
23* [🔨 Commands](#-commands)
24* [🏭 Related Repositories](#-related-repositories)
25* [🦔 Learn More](#🦔-learn-more)
26* [📣 Feedback](#-feedback)
27<!-- tocstop -->
28
29# 🗒 Description
30
31This is a framework for building CLIs in Node.js. This framework was built out of the [Heroku CLI](https://cli.heroku.com) 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).
32
33[See the docs for more information](http://oclif.io/docs/introduction).
34
35# 🚀 Getting Started Tutorial
36
37The [Getting Started tutorial](http://oclif.io/docs/introduction) 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.
38
39# ✨ Features
40
41* **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.
42* **Super Speed** - The overhead for running an oclif CLI command is almost nothing. [It requires very few dependencies](https://www.npmjs.com/package/@oclif/command?activeTab=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.
43* **CLI Generator** - Run a single command to scaffold out a fully functional CLI and get started quickly. See [Usage](#-usage) below.
44* **Testing Helpers** - We've put a lot of work into making commands easier to test and mock out stdout/stderr. The generator will automatically create [scaffolded tests](https://github.com/oclif/example-multi-ts/blob/master/test/commands/hello.test.ts).
45* **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 the [multi-command CLI example](https://github.com/oclif/example-multi-ts)
46* **Plugins** - Using [plugins](https://oclif.io/docs/plugins), 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. See [Building your own plugin](https://oclif.io/docs/plugins#building-your-own-plugin).
47* **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.
48* **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.
49* **Auto-updating Installers** - oclif can package your CLI into [different installers](https://oclif.io/docs/releasing) that will not require the user to already have node installed on the machine. These can be made auto-updatable by using [plugin-update](https://github.com/oclif/plugin-update).
50* **Everything is Customizable** - Pretty much anything can be swapped out and replaced inside oclif if needed—including the arg/flag parser.
51* **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:
52<!--* **Coming soon: man pages** - In addition to in-CLI help through `-help` and the README markdown help generation, the CLI can also automatically create man pages for all of its commands.-->
53
54```
55$ heroku info --app=<tab><tab> # will complete with all the Heroku apps a user has in their account
56```
57
58# 📌 Requirements
59
60Currently, Node 8+ is supported. We support the [LTS versions](https://nodejs.org/en/about/releases) of Node. You can add the [node](https://www.npmjs.com/package/node) package to your CLI to ensure users are running a specific version of Node.
61
62# 🌈 CLI Types
63
64With oclif you can create 2 different CLI types, single and multi.
65
66Single CLIs are like `ls` or `cat`. They can accept arguments and flags. Single CLIs can [optionally be a single file](https://github.com/oclif/command).
67
68Multi CLIs are like `git` or `heroku`. They have subcommands that are themselves single CLIs. In the `package.json` there is a field `oclif.commands` that points to a directory. This directory contains all the subcommands for the CLI. For example, if you had a CLI called `mycli` with the commands `mycli create` and `mycli destroy`, you would have a project like the following:
69
70```
71package.json
72src/
73└── commands/
74    ├── create.ts
75    └── destroy.ts
76```
77
78Multi-command CLIs may also include [plugins](https://oclif.io/docs/plugins).
79
80# 🏗 Usage
81
82Creating a single-command CLI:
83
84```sh-session
85$ npx oclif single mynewcli
86? npm package name (mynewcli): mynewcli
87$ cd mynewcli
88$ ./bin/run
89hello world from ./src/index.js!
90```
91
92Creating a multi-command CLI:
93
94```sh-session
95$ npx oclif multi mynewcli
96? npm package name (mynewcli): mynewcli
97$ cd mynewcli
98$ ./bin/run --version
99mynewcli/0.0.0 darwin-x64 node-v9.5.0
100$ ./bin/run --help
101USAGE
102 $ mynewcli [COMMAND]
103
104COMMANDS
105 hello
106 help display help for mynewcli
107
108$ ./bin/run hello
109hello world from ./src/hello.js!
110```
111
112# 📚 Examples
113
114* TypeScript
115 * [Multi-command CLI](https://github.com/oclif/example-multi-ts)
116 * [Single-command CLI](https://github.com/oclif/example-single-ts)
117 * [Multi-command CLI Plugin](https://github.com/oclif/example-plugin-ts)
118* JavaScript
119 * [Multi-command CLI](https://github.com/oclif/example-multi-js)
120 * [Single-command CLI](https://github.com/oclif/example-single-js)
121 * [Multi-command CLI Plugin](https://github.com/oclif/example-plugin-js)
122
123# 🔨 Commands
124
125<!-- commands -->
126* [`oclif command NAME`](#oclif-command-name)
127* [`oclif help [COMMAND]`](#oclif-help-command)
128* [`oclif hook NAME`](#oclif-hook-name)
129* [`oclif multi [PATH]`](#oclif-multi-path)
130* [`oclif plugin [PATH]`](#oclif-plugin-path)
131* [`oclif single [PATH]`](#oclif-single-path)
132
133## `oclif command NAME`
134
135add a command to an existing CLI or plugin
136
137```
138USAGE
139 $ oclif command NAME
140
141ARGUMENTS
142 NAME name of command
143
144OPTIONS
145 --defaults use defaults for every setting
146 --force overwrite existing files
147```
148
149_See code: [src/commands/command.ts](https://github.com/oclif/oclif/blob/v1.15.2/src/commands/command.ts)_
150
151## `oclif help [COMMAND]`
152
153display help for oclif
154
155```
156USAGE
157 $ oclif help [COMMAND]
158
159ARGUMENTS
160 COMMAND command to show help for
161
162OPTIONS
163 --all see all commands in CLI
164```
165
166_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.1/src/commands/help.ts)_
167
168## `oclif hook NAME`
169
170add a hook to an existing CLI or plugin
171
172```
173USAGE
174 $ oclif hook NAME
175
176ARGUMENTS
177 NAME name of hook (snake_case)
178
179OPTIONS
180 --defaults use defaults for every setting
181 --event=event [default: init] event to run hook on
182 --force overwrite existing files
183```
184
185_See code: [src/commands/hook.ts](https://github.com/oclif/oclif/blob/v1.15.2/src/commands/hook.ts)_
186
187## `oclif multi [PATH]`
188
189generate a new multi-command CLI
190
191```
192USAGE
193 $ oclif multi [PATH]
194
195ARGUMENTS
196 PATH path to project, defaults to current directory
197
198OPTIONS
199 --defaults use defaults for every setting
200 --force overwrite existing files
201 --options=options (yarn|typescript|eslint|mocha)
202```
203
204_See code: [src/commands/multi.ts](https://github.com/oclif/oclif/blob/v1.15.2/src/commands/multi.ts)_
205
206## `oclif plugin [PATH]`
207
208create a new CLI plugin
209
210```
211USAGE
212 $ oclif plugin [PATH]
213
214ARGUMENTS
215 PATH path to project, defaults to current directory
216
217OPTIONS
218 --defaults use defaults for every setting
219 --force overwrite existing files
220 --options=options (yarn|typescript|eslint|mocha)
221```
222
223_See code: [src/commands/plugin.ts](https://github.com/oclif/oclif/blob/v1.15.2/src/commands/plugin.ts)_
224
225## `oclif single [PATH]`
226
227generate a new single-command CLI
228
229```
230USAGE
231 $ oclif single [PATH]
232
233ARGUMENTS
234 PATH path to project, defaults to current directory
235
236OPTIONS
237 --defaults use defaults for every setting
238 --force overwrite existing files
239 --options=options (yarn|typescript|eslint|mocha)
240```
241
242_See code: [src/commands/single.ts](https://github.com/oclif/oclif/blob/v1.15.2/src/commands/single.ts)_
243<!-- commandsstop -->
244
245# 🏭 Related Repositories
246
247* [@oclif/command](https://github.com/oclif/command) - Base command for oclif. This can be used directly without the generator.
248* [@oclif/config](https://github.com/oclif/config) - Most of the core setup for oclif lives here.
249* [@oclif/errors](https://github.com/oclif/errors) - Renders and logs errors from commands.
250* [@oclif/cli-ux](https://github.com/oclif/cli-ux) - Library for common CLI UI utilities.
251* [@oclif/test](https://github.com/oclif/test) - Test helper for oclif.
252
253# 🦔 Learn More
254
255* [Salesforce Release Announcement](https://engineering.salesforce.com/open-sourcing-oclif-the-cli-framework-that-powers-our-clis-21fbda99d33a)
256* [Heroku Release Announcement](https://blog.heroku.com/open-cli-framework)
257
258# 📣 Feedback
259
260If you have any suggestions or want to let us know what you think of oclif, send us a message at <heroku-cli@salesforce.com>