blog

ブログ

SoCal developer building with Ruby, JavaScript and Python.


building a golang CLI tool...

01 Oct 2025

Before I began writing code, I used to wonder: Do people actually use the command line?

It always seemed like this strange, arcane tool…


But now, as a professional programmer, I can’t imagine working without a terminal. Which is why, as part of a recent school assignment, I decided to try writing a command line application. Something useful, for more than just starting servers or interacting with databases. But also something relatively simple: a CLI to-do list!

So I built this CLI application in Go. Why? Well, apart from a recent class I took being about statically-typed languages, and Go specifically, I had been interested in trying Go and as it turns out, Go is a great language for writing command line applications. Many popular command line applications are written in Go, including Docker, Terraform and Github’s gh tool. Go is a great choice when writing CLI applications for a few reasons:


  • Single Binary Distribution: Go compiles to a single binary with no external dependencies so you can just copy one executable file to any machine and it works perfectly
  • Performance: Go is fast, an important feature for command line applications that should feel snappy and responsive
  • Good Ecosystem: Popular libraries, such as Cobra and Bubbletea make it fun and easy to write command line applications


We’re probably all familiar with how to-do lists work, but I want to run through how I built mine, some of the features it offers, and the unique aspects of Go which make this application awesome.


The app is called Tri and as I mentioned it’s a command-line tool. In the same way that we preface Docker commands with docker, i.e. docker build or docker run, we preface all Tri commands with tri. When you’re getting started you can just type triin the command line and it will list the available commands. In my implementation, the available commands are:

  • list
  • add
  • done

For example, to see the todo items in your list, type tri list. To add a todo, use tri add 'thing to add'. And to mark an item as complete, run tri done item-index.

It’s pretty simple but if you get stuck you can ask for help with tri help name-of-command!


How It Works

This app leverages an awesome Go package called Cobra a commander for Go CLI interactions. We import it into a project in a root.go file with:

"github.com/spf13/cobra"

Then we can start writing our supported commands (list, add, done).


but here’s the cool part: Cobra itself is a command line tool! Similar to a Rails generator, we can generate a new command file and all its scaffolding by running:

cobra-cli add list


This generate a cmd/list.go file for us to finish writing Tri’s list command. It’s pretty neat!


For data persistence, I’m using a simple JSON file stored in the user’s home directory. Each todo has an ID, description and completion status. When you run any command, the app reads from this file, makes the necessary changes, and writes it back. Simple and it works great for a personal productivity tool.

I’m going to skip over most of the implementation details but if you’re curious please feel free to explore the repo here.


Why Go Makes This Awesome

Go is a compiled language. Before we can run our code, it first needs to be compiled, typically with the go build command. This takes all our Go code and converts it into machine code, readable by any computer. If someone has this compiled code, they don’t even need Go installed on their computer to run it!

This means Tri is completely portable! Anyone can download the binaries and start using my command line utility immediately. There are no runtime dependencies, no version conflicts and no installation headaches. Even better than this, Go supports cross-compilation out of the box so I could build binaries for Windows, MacOS and Linux all from my machine with build flags.

No more “works on my machine” problems or complex setup instructions. This is game-changer for distribution and one of the wonderful aspects of writing a CLI tool in Go! ☺️


Building this CLI tool helped show me why Go has become so popular for developer tooling. The combination of simplicity, performance and effortless distribution makes it perfect for creating utilities. Plus, there’s something deeply satisfying about building a tool that lives in the terminal, that place where developers spend so much of their time, that I can actually use!