oclif is a framework for building CLIs in Node. It can be used like a simple flag parser but is capable of much more. It's designed to be extensible so that you can easily add plugins such as the update warning plugin or build your own for users to install at runtime.
Everything is customizable in oclif. Even the flag parser and help generation is optional and can be replaced. It's a platform to build upon that provides smart defaults without locking you in to any specific tools or behavior.
Single-command or Multi-command
With oclif you can create 2 different CLI types: single and multi.
Single CLIs are like
curl. They can accept arguments and flags. Single CLIs can optionally be just a single file.
Multi CLIs are like
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.
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!