← BackHow do I implement a command line tool?u11g.com
1/4/2020

How do I implement a command line tool?

Define MVP

I’m a software engineer, so I expect a direction in which a product should be developed, and then I decide how the product will be implemented. In this case I am also the product owner. Since I want to solve a personal problem it is relatively simple. I am the target group, so I decide what is the minimum that needs to be implemented before the product can be shipped. My requirements are clear, tasks can be derived from this:

  • Command line tool that can be used globally
  • Simple search for commands
  • Easy extensibility of commands

Select technology stack

In this area developers feel much more comfortable ;) Since I’ve been mostly in the node universe lately and npm is a widely used package manager available on Linux, MacOS and Windows systems, the decision was quite easy for me:

node
npm
  • The logic is implemented in TypeScript and Node.
  • The tool will be released on npmjs.
  • The project is hosted as an open source project at GitHub.

Implement core logic and CLI interface

I don’t want to go too deep into details, the project can be viewed at GitHub. There are a few things I want to highlight though, as I’m sure you’ll find them interesting: inquirer-autocomplete-prompt is a very simple and nice input library that is well configurable. It allows you to search for an entry in an array and have it output to the terminal without any custom development. Every command line tool has a version number, a help, can process parameters or flags if necessary. Nowadays nobody has to implement this himself. meow gives us a basic framework that only needs to be filled up.

Provide first cheatsheets

This is necessary so that a user can use the tool immediately: no one wants to install a tool and then has to specify long configurations that are needed to use the tool. I personally need kubectl commands again and again, whose syntax I have to look up (unfortunately too often). Furthermore there are some zsh git shortcuts for which I have to look into the cheatsheet from time to time. So I’ve prepared something for them. As a bonus there are gitmojis ;)

Publish

There is not much to tell about this point: an npmjs account is quickly set up, customize the project accordingly and run npm publish.

npm publish

What do I get out of it now?

I personally have made my life a little bit easier. I now get commands much faster that I can’t remember. If there is another command that seems useful but is not used very often, I can simply add it to the list and that’s it. I also have a simple blueprint that I can use to write more tools if I need them. And maybe it helps the one or other reader too ;)

Home
Projects
Newsletter
Blog
Me
Philosophy
Gen Art
Work
Setup
CV
Machine
Dynamic Pong: Territory Conquest Meets Classic Physics
Introducing Camunda Directory
Getting Started with AIME Directory Collections in 5 Minutes
How to use a proxy in a nodejs environment
Introducing weeklyfoo
Create your own epaper calendar with Canvas
Codespaces can become a game changer
Cloudflare pages direct upload with stable preview urls
Building your own Twitter Thread Generator
300 APIs integrated in minutes, not days
Be an orchestration hero
Cut a few braids - new NPM package
ETHme - your chic web3 identity
Automatically update data and commit
Aren't the standard actions going too far for you? Write your own one!
Screenshots - a perfect task to automate!
Send messages to Slack from Camunda Cloud
5 Steps how to track your Team's Mood
Automate your manual tasks with Camunda and Trello!
Go beyond the basics
Is there an alternative to spaghetti?
Play with node-canvas and build something useful
How do I implement a command line tool?
Aime Directory
Boring Dev Tools
Camunda Directory
Data Democracy
Dev Pulse
Dynamic Pong
Lifosy
Art u11g
dapphuntr
DiyPunks
flethy
Maker Oracles
SwagTime
EthME
fcheat
Find the next victim
Generative Arts
MakerDAO Delegates
SkunkWorks NFT
Trees of Life NFT
zukuNFT
RestZeebe
Websiteshot
Zeebetron: How to Manage Multiple Zeebe Profiles with Electron
dot calendar
Sharu
Switch Interface (theme)
LINKEDIN
X
GITHUB