Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python.<p>It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might be a good choice for prototyping.<p>I actually started learning Go with CLI applications. I have found that <a href="https://github.com/spf13/cobra" rel="nofollow">https://github.com/spf13/cobra</a> tends to be one of the better CLI helpers you can get into but <a href="https://github.com/jpillora/opts" rel="nofollow">https://github.com/jpillora/opts</a> is one I have been meaning to try following a presentation I saw on it once.
Since everyone else is throwing out recommendations I personally think <a href="https://github.com/spf13/cobra" rel="nofollow">https://github.com/spf13/cobra</a> is the best CLI templating system, especially because of how well it pairs with <a href="https://github.com/spf13/viper" rel="nofollow">https://github.com/spf13/viper</a>.<p>Large projects like Hugo and Kubernetes have used Cobra to build their CLI tools, and it's fairly light as well even if you need simpler usage. We use it at my workplace simply for wrapping our microservices and the few commands (serve, migrate, etc)
My Opinion:<p>The best cli lib I found:
<a href="https://github.com/urfave/cli" rel="nofollow">https://github.com/urfave/cli</a><p>For deployment I recommend:
<a href="https://github.com/goreleaser/goreleaser" rel="nofollow">https://github.com/goreleaser/goreleaser</a><p>During development I recommend:
<a href="https://github.com/golangci/golangci-lint" rel="nofollow">https://github.com/golangci/golangci-lint</a> and <a href="https://github.com/stretchr/testify" rel="nofollow">https://github.com/stretchr/testify</a>
Everyone's throwing out suggestions for CLI libraries, so let me plug my mate's: <a href="https://github.com/jpillora/opts" rel="nofollow">https://github.com/jpillora/opts</a><p>I definitely prefer it to cobra
I wrote a Go CLI Boilerplate sometime back: <a href="https://github.com/pulkitsharma07/go-cli-boilerplate" rel="nofollow">https://github.com/pulkitsharma07/go-cli-boilerplate</a>, it addresses some common issue which I faced while developing a full-fledged CLI.<p>Features (From Readme):<p>* Unit and Integration test structure for the CLI<p>* Opinionated directory structure for organizing code for commands.<p>* Docker-based cross-platform build pipeline<p>* Travis CI-based release workflow<p>* Makefile for common tasks like generating documentation and building the binary.
I love using Go for CLIs. Previously, I developed CLIs with JavaScript (NodeGH, something with the same goal as GitHub's CLI), and "kind of" with PHP as well (for internal tasks on a server). Nothing compares with writing one with Go, though.<p>I used to be the maintainer of a CLI for a PaaS until a year ago:
<a href="https://asciinema.org/a/192043" rel="nofollow">https://asciinema.org/a/192043</a>
<a href="https://github.com/henvic/wedeploycli" rel="nofollow">https://github.com/henvic/wedeploycli</a>
If anyone would like a book on this subject, I recommend <i>Powerful Command-Line Applications in Go</i>: <a href="https://pragprog.com/book/rggo/powerful-command-line-applications-in-go" rel="nofollow">https://pragprog.com/book/rggo/powerful-command-line-applica...</a><p>It's currently in Beta but the first 6 chapters are finished and available. As someone learning Go I found it a nice complement to reading <i>The Go Programming Language</i>.
I've been building CLIs with Go as part of a 52 projects in 52 weeks challenge[1] and I'm loving it so far. I released a batch renaming tool [2] just a few days ago.<p>[1]: <a href="https://github.com/ayoisaiah/project52" rel="nofollow">https://github.com/ayoisaiah/project52</a>
[2]: <a href="https://github.com/ayoisaiah/goname" rel="nofollow">https://github.com/ayoisaiah/goname</a>
Whatever you do, do not use the flag library in a package that might ever, EVER be imported. Google did this in the horribly written glog port to go which until recently was used everywhere in Kubernetes. The only way to determine the value of the "v" flag they define globally for your entire executable is to call the V(n) function with n incrementing until it returns false.<p>pflag, which is used by cobra, is a much nicer library.
I wrote my own flags package called flaggy and think its the easiest to use and makes the most sense! Up to 600 stars om github now.
<a href="https://github.com/integrii/flaggy" rel="nofollow">https://github.com/integrii/flaggy</a>
I want something like Argh (<a href="https://github.com/neithere/argh/" rel="nofollow">https://github.com/neithere/argh/</a>) but for Go... any hint ? There are a gazillion cli libs, it's hard to test all of them.
Is it possible to display images in terminal?<p>Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.
Wow talk about timing. I just created a simple Markdown viewer with a CSS switcher.<p>Shameless promotion:<p><a href="https://github.com/christiansakai/md" rel="nofollow">https://github.com/christiansakai/md</a>
As much as I like Go I don't think it's ideal for CLI apps.<p>IMO Python is the best at creating simple to complex CLI apps due to it being interpreted and simple. It's an overcharged bash.
Is Go a good option to create some background tasks. For eg. monitor which Spotify songs are playing and and store that in a json file, etc. Or is Python more suitable for this?
Just a note, xkcd has 2 image sizes.<p>Small: <a href="https://imgs.xkcd.com/comics/confidence_interval.png" rel="nofollow">https://imgs.xkcd.com/comics/confidence_interval.png</a><p>Big: <a href="https://imgs.xkcd.com/comics/confidence_interval_2x.png" rel="nofollow">https://imgs.xkcd.com/comics/confidence_interval_2x.png</a><p>Though not for older ones.
I had a similar idea a couple of months ago. Make a CLI in golang that allows me to easily open all my favorite timewaster sites at the start of the work day. But it ended up in the "Started, but never looked at again" pile. Maybe I'll have another look at it on the weekend.
I personally love building CLI tools in Node, since I and my co-workers all have it installed. Nice synchronous STD lib for file manipulation and async/await makes for compact async code.<p>If I worked in a Go shop I'd probably use Go, though.
Took your code, added a random number generator and threw it into a Go HTTP server and deployed it as a GCP Cloud Function :-)<p><a href="https://us-central1-bookshelf-app-1103.cloudfunctions.net/RandomXkcd" rel="nofollow">https://us-central1-bookshelf-app-1103.cloudfunctions.net/Ra...</a><p>Voila!! Serverless Random XKCD..
Have a look at <a href="https://github.com/hofstadter-io/hofmod-cli" rel="nofollow">https://github.com/hofstadter-io/hofmod-cli</a><p>It makes framing out advanced Golang CLIs a breeze<p>*(creator)
Seems overcooked in some places and undercooked in others. I of course prefer my own CLI template but so it goes: <a href="https://github.com/carlmjohnson/go-cli" rel="nofollow">https://github.com/carlmjohnson/go-cli</a>