Developers love CLI tools! So much so that I’m sure we would jump at the chance to do everything on a computer with the comfort of a command line. And why not do just that? With the help of modern libraries and frameworks, building our own CLI is a matter of a few hours or even minutes. Especially in Node, you can easily build exciting command-line interfaces using the oclif framework.
In this article, we are going to create a simple CLI tool to help us track our weight over time. It has simple features like adding a new weight record and displaying past records.
Since we are using oclif to easily complete this task, let’s try to understand exactly what it is.
Oclif is a framework used for creating CLI tools in Node. It supports both JavaScript and TypeScript implementations. Oclif provides a rich set of features to design and implement command-line programs that are easily extendable with plug-ins and hooks.
We can create two types of command-line tools in Oclif: single- and multi-command. Single-command CLIs provide only one command option (similar to ls
and curl
commands in Linux). Multi-command programs support subcommands that proceed the main command. git
and npm
are good examples of multi-command tools.
In this tutorial, we are building a multi-command program that supports add
and show
subcommands to add new weight records and display old records.
#nodejs #javascript #software-development