Skip to main content

At the beginning, CLI is better known as the only way to interact with a computer. It has been existed even before there are graphical interfaces and flashy user desktops. Through CLI, you can accept text commands and interpret them into functions on the operating system. However, the CLI has become a vital element to cloud computing management, due to its developer appeal and scripting capabilities, but more and more API-related companies are beginning to offer a CLI on the side of their API as well.

In this article, we’ll show you how CLI can work alongside with API to maximize their platform usage.  In fact, some API-related companies realize that offering a CLI could improve their third-party web developer experience.

Best Practices for Offering a CLI
As we face the growing trend of CLI support across the industry, so what are the best practices  for maintaining one?

Juniper vs. Cisco: To know which CLI style families work best for you, you can compare the two main CLI style families. Some developers are fond of Juniper style for its consistency, structure, and well-defined elements.

Design it to be transactional: Working in CLI will require you to be able to prepare your configuration, validate it, compare it with what you have, and then in the end, commit it in one single step.

Clearly separate operational and configuration data: Things which are considered as operational data are statistics and uptime. The differentiation should be obvious in the design. Ideally, your configuration should never depend on operational state:

“An example is an interface that can only be configured if it’s connected to the Internet. This means that the configuration may have been valid when the admin set it the first time, but when internet connection goes down, what will  you do then? The configuration is suddenly invalid. This is a bad property of a system. It makes it very hard to pre-provision a system, since you cannot tell beforehand if the configuration is valid or not.”

Let the model drive the CLI for ultimate consistency. For Amazon, in order to reach a consistent command line experience across thousands of commands, they did the following steps:

“We decided to auto-generate commands and options from the underlying models that describe AWS APIs. This strategy has enabled us to deliver timely support for new AWS services and API updates with a consistent style of commands.”

Shoot for CLI-API-GUI parity: If you follow a model-driven paradigm, every single CLI command should be accessible as an API call, and vice versa. As API evangelists’ notes, the AWS API and CLI are pretty much in sync in terms of functionalities:

“Making sure there is parity and consistency between what is available via a UI, and the API and CLI is important.”

When updating, it is important to be careful about evolvability. Moreover, command documentation, API docs, and functionality must remain in sync.

Adam Duvander of Zapier lists some great CLI best practices in his article here, some of which are summarized below.

  • Provide a help screen: Usability and discovery are very important for CLIs. Make accessing a Getting Started guide easy with simple flags like –h or ?
  • Offer tab completion.
  • S Replicate patterns from Linux commands that work, and take advantage of succinct commands.
  • Offer customization options.
  • Make security a high priority.
  • If desktop-based, support different Oss and developer environments so that no teammate is left in the lurch.

Benefits
Nowadays, more API providers are supporting a CLI alongside their API. This arises so many curiosities, if you are one among so many people who are curious why many people provide a CLI alongside an API offering:

The main reason why developers love to work with CLI is that it keeps developers where they work. Moreover, with CLI, you can ensure whether it is making a human readable interface to better appeal to developer tastes, automating tedious UI actions, or offering new scripting capabilities to accelerate your continuous delivery.

Conclusion: Is CLI-first the new API-First?
Choosing a CLI is a good choice, especially for improving developer experience. This is because CLI can be used in an interactive mode to debug, troubleshot, or explore in real time, or used in a high-level, abstracted way with shell scripts to unite local and CLI actions.

You can apply CLIs in cloud computing, but also found emerging CLI support among other sectors, such as API gateway layers like Mashape’a Kong, identity specialists like Curity.io, documentation generators like Apiary, CMSs like WordPress , and micro-app integrators like Zapier are all spearheading CLIs to offer nuanced controls. Moreover, CLI-first won’t likely replace the “API-first” mantra; since a quality designed CLI is based on an API.