Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-oclif

Package Overview
Dependencies
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-oclif

oclif: create your own CLI

  • 1.7.35
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27
increased by42.11%
Maintainers
2
Weekly downloads
 
Created
Source

oclif: Node.JS Open CLI Framework

Join the chat at https://gitter.im/oclif/oclif Version CircleCI Appveyor CI Greenkeeper Known Vulnerabilities Downloads/week License

🗒 Description

This is a framework for building CLIs in Node.js. This framework was built out of the Heroku CLI 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).

See the docs for more information.

🚀 Getting Started Tutorial

The Getting 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.

✨ Features

  • 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.
  • Super Speed - The overhead for running an oclif CLI command is almost nothing. It requires very few 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.
  • CLI Generator - Run a single command to scaffold out a fully functional CLI and get started quickly. See Usage below.
  • 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.
  • 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
  • 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.
  • 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 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.
  • Everything is Customizable - Pretty much anything can be swapped out and replaced inside oclif if needed—including the arg/flag parser.
  • 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.
  • 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:
$ heroku info --app=<tab><tab> # will complete with all the Heroku apps a user has in their account

📌 Requirements

Only 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 package to your CLI to ensure users are on Node 8.

🌈 CLI Types

With oclif you can create 2 different CLI types, single and multi.

Single CLIs are like ls or cat. They can accept arguments and flags. Single CLIs can optionally be just be a single file.

Multi 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:

package.json
src/
└── commands/
    ├── create.ts
    └── destroy.ts

Multi-command CLIs may also include plugins.

🏗 Usage

Creating a single-command CLI:

$ npx oclif single mynewcli
? npm package name (mynewcli): mynewcli
$ cd mynewcli
$ ./bin/run
hello world from ./src/index.js!

Creating a multi-command CLI:

$ npx oclif multi mynewcli
? npm package name (mynewcli): mynewcli
$ cd mynewcli
$ ./bin/run --version
mynewcli/0.0.0 darwin-x64 node-v9.5.0
$ ./bin/run --help
USAGE
  $ mynewcli [COMMAND]

COMMANDS
  hello
  help   display help for mynewcli

$ ./bin/run hello
hello world from ./src/hello.js!

📚 Examples

🔨 Commands

oclif command NAME

add a command to an existing CLI or plugin

USAGE
  $ oclif command NAME

ARGUMENTS
  NAME  name of command

OPTIONS
  --defaults  use defaults for every setting
  --force     overwrite existing files

See code: src/commands/command.ts

oclif help [COMMAND]

display help for oclif

USAGE
  $ oclif help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

oclif hook NAME

add a hook to an existing CLI or plugin

USAGE
  $ oclif hook NAME

ARGUMENTS
  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

oclif multi [PATH]

generate a new multi-command CLI

USAGE
  $ oclif multi [PATH]

ARGUMENTS
  PATH  path to project, defaults to current directory

OPTIONS
  --defaults         use defaults for every setting
  --force            overwrite existing files
  --options=options  (yarn|typescript|tslint|semantic-release|mocha)

See code: src/commands/multi.ts

oclif plugin [PATH]

create a new CLI plugin

USAGE
  $ oclif plugin [PATH]

ARGUMENTS
  PATH  path to project, defaults to current directory

OPTIONS
  --defaults         use defaults for every setting
  --force            overwrite existing files
  --options=options  (yarn|typescript|tslint|semantic-release|mocha)

See code: src/commands/plugin.ts

oclif single [PATH]

generate a new single-command CLI

USAGE
  $ oclif single [PATH]

ARGUMENTS
  PATH  path to project, defaults to current directory

OPTIONS
  --defaults         use defaults for every setting
  --force            overwrite existing files
  --options=options  (yarn|typescript|tslint|semantic-release|mocha)

See code: src/commands/single.ts

🦔 Learn More

📣 Feedback

If 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

Keywords

FAQs

Package last updated on 21 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc