UNPKG

10.8 kBMarkdownView Raw
1oclif: Node.JS Open CLI Framework
2=================================
3
4[![Join the chat at https://gitter.im/oclif/oclif](https://badges.gitter.im/oclif/oclif.svg)](https://gitter.im/oclif/oclif?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5[![Version](https://img.shields.io/npm/v/oclif.svg)](https://npmjs.org/package/oclif)
6[![CircleCI](https://circleci.com/gh/oclif/oclif/tree/master.svg?style=shield)](https://circleci.com/gh/oclif/oclif/tree/master)
7[![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)
8[![Greenkeeper](https://badges.greenkeeper.io/oclif/oclif.svg)](https://greenkeeper.io/)
9[![Known Vulnerabilities](https://snyk.io/test/github/oclif/oclif/badge.svg)](https://snyk.io/test/github/oclif/oclif)
10[![Downloads/week](https://img.shields.io/npm/dw/oclif.svg)](https://npmjs.org/package/oclif)
11[![License](https://img.shields.io/npm/l/oclif.svg)](https://github.com/oclif/oclif/blob/master/package.json)
12
13<!-- toc -->
14* [🗒 Description](#-description)
15* [🚀 Getting Started Tutorial](#-getting-started-tutorial)
16* [✨ Features](#-features)
17* [📌 Requirements](#-requirements)
18* [🌈 CLI Types](#-cli-types)
19* [🏗 Usage](#-usage)
20* [📚 Examples](#-examples)
21* [🔨 Commands](#-commands)
22* [🏭 Related Repositories](#-related-repositories)
23* [🦔 Learn More](#-learn-more)
24* [📣 Feedback](#-feedback)
25<!-- tocstop -->
26
27# 🗒 Description
28
29This 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 simple CLIs that can be just a single file with a few flag options, or for very complex CLIs that have subcommands (like git or heroku).
30
31[See the docs for more information](http://oclif.io/docs/introduction.html).
32
33# 🚀 Getting Started Tutorial
34
35The [Getting Started tutorial](http://oclif.io/docs/introduction.html) 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.
36
37# ✨ Features
38
39* **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 easily use the CLI in ways they expect, but without comprisiming strictness guarantees to the developer.
40* **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). Also, only the command to be executed will be required with node. So large CLIs with many commands will load just as fast as a small one with a single command.
41* **CLI Generator** - Run a single command to scaffold out a fully functional CLI and get started quickly. See [Usage](#-usage) below.
42* **Testing Helpers** - We've put a lot of work into making commands easily testable and easy to 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).
43* **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)
44* **Plugins** - Using 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.html#building-your-own-plugin).
45* **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.
46* **TypeScript (or not)** - Everything in the core of oclif is written in TypeScript and the generator can build fully configured TypeScript CLIs or just 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 making it easy and fast to use TypeScript with minimal-to-no boilerplate needed for any oclif CLI.
47* **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.
48* **Coming soon: Autocomplete** - Automatically include autocomplete for your CLI. This includes not just command names and flag names, but flag values as well. For example, it's easy to configure the Heroku CLI to have completions for Heroku app names:
49
50```
51$ heroku info --app=<tab><tab> # will complete with all the Heroku apps a user has in their account
52```
53
54# 📌 Requirements
55
56Only Node 8+ is supported. Node 6 will reach end-of-life April 2019. At that point we will continue to support the current LTS version of node. You can add the [node](https://www.npmjs.com/package/node) package to your CLI to ensure users are on Node 8.
57
58# 🌈 CLI Types
59
60With oclif you can create 2 different CLI types, single and multi.
61
62Single CLIs are like `ls` or `cat`. They can accept arguments and flags. Single CLIs can [optionally be just be a single file](https://github.com/oclif/command).
63
64Multi 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:
65
66```
67package.json
68src/
69└── commands/
70    ├── create.ts
71    └── destroy.ts
72```
73
74Multi-command CLIs may also include [plugins](https://oclif.io/docs/plugins.html).
75
76# 🏗 Usage
77
78Creating a single-command CLI:
79
80```sh-session
81$ npx oclif single mynewcli
82? npm package name (mynewcli): mynewcli
83$ cd mynewcli
84$ ./bin/run
85hello world from ./src/index.js!
86```
87
88Creating a multi-command CLI:
89
90```sh-session
91$ npx oclif multi mynewcli
92? npm package name (mynewcli): mynewcli
93$ cd mynewcli
94$ ./bin/run --version
95mynewcli/0.0.0 darwin-x64 node-v9.5.0
96$ ./bin/run --help
97USAGE
98 $ mynewcli [COMMAND]
99
100COMMANDS
101 hello
102 help display help for mynewcli
103
104$ ./bin/run hello
105hello world from ./src/hello.js!
106```
107
108# 📚 Examples
109
110* TypeScript
111 * [Multi-command CLI](https://github.com/oclif/example-multi-ts)
112 * [Single-command CLI](https://github.com/oclif/example-single-ts)
113 * [Multi-command CLI Plugin](https://github.com/oclif/example-single-ts)
114* JavaScript
115 * [Multi-command CLI](https://github.com/oclif/example-multi-js)
116 * [Single-command CLI](https://github.com/oclif/example-single-js)
117 * [Multi-command CLI Plugin](https://github.com/oclif/example-plugin-js)
118
119# 🔨 Commands
120
121<!-- commands -->
122* [oclif command NAME](#oclif-command-name)
123* [oclif help [COMMAND]](#oclif-help-command)
124* [oclif hook NAME](#oclif-hook-name)
125* [oclif multi [PATH]](#oclif-multi-path)
126* [oclif plugin [PATH]](#oclif-plugin-path)
127* [oclif single [PATH]](#oclif-single-path)
128
129## oclif command NAME
130
131add a command to an existing CLI or plugin
132
133```
134USAGE
135 $ oclif command NAME
136
137ARGUMENTS
138 NAME name of command
139
140OPTIONS
141 --defaults use defaults for every setting
142 --force overwrite existing files
143```
144
145_See code: [src/commands/command.ts](https://github.com/oclif/oclif/blob/v1.7.5/src/commands/command.ts)_
146
147## oclif help [COMMAND]
148
149display help for oclif
150
151```
152USAGE
153 $ oclif help [COMMAND]
154
155ARGUMENTS
156 COMMAND command to show help for
157
158OPTIONS
159 --all see all commands in CLI
160```
161
162_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v1.2.1/src/commands/help.ts)_
163
164## oclif hook NAME
165
166add a hook to an existing CLI or plugin
167
168```
169USAGE
170 $ oclif hook NAME
171
172ARGUMENTS
173 NAME name of hook (snake_case)
174
175OPTIONS
176 --defaults use defaults for every setting
177 --event=event [default: init] event to run hook on
178 --force overwrite existing files
179```
180
181_See code: [src/commands/hook.ts](https://github.com/oclif/oclif/blob/v1.7.5/src/commands/hook.ts)_
182
183## oclif multi [PATH]
184
185generate a new multi-command CLI
186
187```
188USAGE
189 $ oclif multi [PATH]
190
191ARGUMENTS
192 PATH path to project, defaults to current directory
193
194OPTIONS
195 --defaults use defaults for every setting
196 --force overwrite existing files
197 --options=options (yarn|typescript|tslint|semantic-release|mocha)
198```
199
200_See code: [src/commands/multi.ts](https://github.com/oclif/oclif/blob/v1.7.5/src/commands/multi.ts)_
201
202## oclif plugin [PATH]
203
204create a new CLI plugin
205
206```
207USAGE
208 $ oclif plugin [PATH]
209
210ARGUMENTS
211 PATH path to project, defaults to current directory
212
213OPTIONS
214 --defaults use defaults for every setting
215 --force overwrite existing files
216 --options=options (yarn|typescript|tslint|semantic-release|mocha)
217```
218
219_See code: [src/commands/plugin.ts](https://github.com/oclif/oclif/blob/v1.7.5/src/commands/plugin.ts)_
220
221## oclif single [PATH]
222
223generate a new single-command CLI
224
225```
226USAGE
227 $ oclif single [PATH]
228
229ARGUMENTS
230 PATH path to project, defaults to current directory
231
232OPTIONS
233 --defaults use defaults for every setting
234 --force overwrite existing files
235 --options=options (yarn|typescript|tslint|semantic-release|mocha)
236```
237
238_See code: [src/commands/single.ts](https://github.com/oclif/oclif/blob/v1.7.5/src/commands/single.ts)_
239<!-- commandsstop -->
240
241# 🏭 Related Repositories
242
243* [@oclif/command](https://github.com/oclif/command) - Base command for oclif. This can be used directly without the generator.
244* [@oclif/config](https://github.com/oclif/config) - Most of the core setup for oclif lives here.
245* [@oclif/errors](https://github.com/oclif/errors) - Renders and logs errors from commands.
246* [@oclif/cli-ux](https://github.com/oclif/cli-ux) - Library for common CLI UI utilities.
247* [@oclif/test](https://github.com/oclif/test) - Test helper for oclif.
248
249# 🦔 Learn More
250
251* [Salesforce Release Announcement](https://engineering.salesforce.com/open-sourcing-oclif-the-cli-framework-that-powers-our-clis-21fbda99d33a)
252* [Heroku Release Announcement](https://blog.heroku.com/open-cli-framework)
253
254# 📣 Feedback
255
256If you have any suggestions or just want to let us know what you think of oclif, send us a message at <heroku-cli@salesforce.com>