How CLI improves local development and application management

Typical developer's workflow involves interacting with terminal usually quite a lot. We use tools provided by our programming environment (to install packages, enter REPL, build the project) and installed libraries. But how many developers create their own tooling? From my experience it's not common practice, especially in small projects.

My field of expertise is backend development, writing web apps in NodeJS in particular. I deal with databases, message queues, APIs, testing, deployment, integration, CI and everything related. Most of my work oscillates between doing some things in the terminal and writing code, and I noticed that having simple and straightforward custom CLI adjusted to my project requirements is a life-saver. The CLI can be just a set of scripts, however proper CLI makes it easier to share with teammates. Whenever I feel like I want my database seeded with random data, some testing message pushed to a message queue, notification published, run some sort of an maintenance task, I just spin-up my CLI, and let it do the work. In the past I was adding functions directly to the application code to do all of that, start the actual app once, have the functions executed, and close the app. This was extremely tedious.

"CLIs" I usually see are dumb aliases for other commands. This is the situation in most NodeJS I've seen - it's even worse there, because npm scripts everybody uses are not well-suited for the actual job. They are only aliases in fact. npm scripts is a common name for a map of chosen command names to commands that are supposed to run on a machine, written in package.json file.

CLI can provide a value! First and foremost it functions as a documentation. This is especially handy when it comes to integration with external services, especially those that require some sort of a setup. CLI can have a command to prepare that setup for us using integration's API. In fact we can play with the integration just using the CLI, and only then implement everything in the actual application's code. CLI will serve post-mortem as an example of simple integration, without all the shenanigans that production code requires.

Secondly, it enforces us to rethink application's design (usually for the better), as now there is another way to access the same business logic besides typical HTTP API. It might lead to modularization and layering, that long term makes application healthier.

Thirdly, it makes onboarding new teammates easier, as now they can have a tool to interact with the application without knowing all the internal details. CLI can prepare environment for testing or local development, and be used not only locally, but in CI flow as well. It might be a developer's gateway to the application.

Last but not least CLI can be used to manage application both locally and in production. CLI can run tasks like cleanup, upgrade, migrations. Maybe it can expose some useful debugging functions as well. Sky is the limit here. Being closely to the actual code, CLIs rarely become obsolete.