Go is great for building command-line applications. We built one: Dolt, the world's first version-controlled SQL database. We wrote our own command li

Building an interactive shell in Golang

submited by
Style Pass
2024-03-30 03:30:02

Go is great for building command-line applications. We built one: Dolt, the world's first version-controlled SQL database. We wrote our own command line parser for handling all of Dolt's subcommands and arguments, but maybe we shouldn't have. There are lots of great ones out there that if we might have used instead if we were starting the project today:

This blog will teach you how to use the best option we know of, abiosoft/ishell, and discuss how to get the most out of it. You'll learn how to configure the interactive shell with the commands you want to handle, how to quit the shell, and how to use the built-in quality-of-life features of the package. We'll also show how we used it to build Dolt's built-in SQL shell capabilities.

So that's what a shell does, and how it differs from normal command-line applications: you have a loop where you accept user input over and over, giving answers or doing other work, until the user decides to exit with a predefined command.

The original abiosoft/ishell package is built to process predefined commands, where each command dispatches to a different handler. In action, this looks like:

Leave a Comment