đī¸ Commands
A basic command looks like the following in TypeScript:
đī¸ Command Arguments
Arguments are positional arguments passed to the command. For example, if this command was run with mycli arg1 arg2 it would be declared like this:
đī¸ Command Flags
Flag options are non-positional arguments passed to the command. Flags can either be option flags which take an argument, or boolean flags which do not. An option flag must have an argument.
đī¸ Config
Inside a command, this.config provides access to the Config class, which contains useful properties and methods you can use in your command. Here are a list of its methods and properties:
đī¸ Command Discovery Strategies
When oclif loads a plugin is must find all the commands within that plugin that can be executed. There a three strategies for discovering these commands:
đī¸ Topics
As CLIs grow it can be useful to nest commands within topics. This is supported simply by placing command files in subdirectories. For example, with the Salesforce CLI we have a topic sf config with commands like sf config set and sf config get. The directory structure looks like this:
đī¸ Topic Separators
By default, topics will be separated with colons, e.g. mycommand. However, you have the option to use spaces if you prefer, e.g. my awesome command.
đī¸ Hooks
oclif exposes lifecycle event hooks such as init and commandnotfound. See below for a list of all the lifecycle events. In addition to these built-in events, you can create your own events and allow commands/plugins to watch for these custom events. It's a great way to allow multiple plugins to interact with each other.
đī¸ Plugins
Plugins are a great way to offer experimental functionality, allow users to extend your CLI, break up a CLI into modular components, or share functionality between CLIs.
đī¸ Help Classes
Out of the box oclif provides a great help experience for CLIs. Users can invoke help with the --help flag.
đī¸ Performance
oclif supports performance tracking out of the box - both for oclif and you own code. You can enable it in one of two ways depending on how you've implemented your bin scripts.