The CLI starter kit. Contribute to charmbracelet/fang development by creating an account on GitHub.
I’ve been maintaining rust-starter[!] for quite sometime now. It is kind of the equivalent of fang but for Rust. It uses Clap which is the equivalent of Cobra; though I don’t think Clap has the same kind of fancy output?
Throughout these years, I have found that cross-compiling is the most challenging part of creating a CLI. When you are building a web back-end, you control the execution environment (usually linux). For CLIs, your users could be on Linux, macOS or Windows. You need to get three x2 binaries (so a total of 6) to have a fair coverage.
I’ve tried cross, but for Windows and macOS you need licenses. There is no straightforward way to give your users Docker images and have them running in a few commands. You can compile on GitHub action machines, but that’s a very slow feedback loop. I wonder if things are better in Go land.
Golang itself bundles a toolchain and can cross compile to a many target OSes and architectures. I use Goreleaser [1] to create GitHub releases, Homebrew packages, Docker images, and Linux packages. Goreleaser Pro can also create MSI packages.
ETA since I just saw Christian chime in: the Goreleaser author works at Charm.sh =)
GoReleaser is indeed an awesome tool and we use it for every applicable project.
And actually Carlos, who builds GoReleaser, is the true author of Fang and took it from concept to execution.
I feel your pain. That said, cross compiling from Go is pretty trivial, as long as everything is pure Go, which it most often is. That’s one if the reasons we invested in jt.
(Hello from Charm! I’m one of the authors of this library.)
Wow TIL cross compilation is a bit of a pain in Rust. I assumed it was as easy as Go. I can confirm as long as you're using pure Go (no cgo), it's as easy as setting $GOOS and $GOARCH appropriately.
The difficulty is due to Rust dynamically linking and Go statically linking. The former requires the system libs.
That said, I am unfamiliar with any licensing for Windows builds.
MacOS has some niche (usually discarded) technicalities like you can only use the SDK on Apple hardware.
I think that's a reference to the use of Docker in the "cross" tool that makes cross compilation easier but I'm not certain
I looked into how rust does does it for rustup, and they have a pretty amazing set of gh actions to build for their architectures, I can't find the GH link now tho
for speed you can look for vendors like https://depot.dev/
This is great, lots I learned by looking at your code and the dependencies you use!
I started a similar thing, although not as feature-rich as yours. My goal was to follow CLI best practices and add all the boilerplate one needs to build a Rust CLI.
I configure github actions to build each version in its natural habitat.
Though my motivation for this was getting the builds off my machine. I didn't want to be shipping binaries I had built locally.
I just ran across "gum"[1] from charmbracelet which I intend to use! I just want to replace dialog. I came across whiptail, too, but gum seems nicer.
They have a TUI framework, too, among a lot of other related things. Some of their projects are Go libraries, some are a CLI tool, such as gum.
Gum looks awesome. Gonna keep it in-mind next time I need to write a shell CLI.
It would be really cool if Fang could generate a TUI form for your app with https://github.com/charmbracelet/huh (by the same org). Is something like that on the roadmap?
Similar work: https://github.com/chriskiehl/Gooey and https://github.com/Sorcerio/Argparse-Interface
I've wanted to do TUI form generation for my own CLI framework since 2023 ( https://github.com/bbkane/warg/issues/71 ), but I still haven't gotten around to it