Let's face it, go is an excellent tool to build self contained clis, however there is always a question of distribution. You could ask your friends to download new binary from the releases page, however wouldn't it be cooler to have a cli that can report about updates and update itself?
This has been done many times, however kleiner allows to do that at scale since it's so damn easy to generate yet another cli and have it's distribution set up immediately. All you need to do is to add your commands and you're done.
We don't need to have another tool for scaffolding, hence please have cobra-cli installed.
Dependencies:
- goreleaser to build binaries for us
- git && github to keep the project and do releases
- go to build the project
GITHUB_TOKEN
in the shell environment
Download kleiner
and install into a local bin directory.
Latest version:
curl -L https://raw.githubusercontent.com/can3p/kleiner/main/generated/install.sh | sh
Specific version:
curl -L https://raw.githubusercontent.com/can3p/kleiner/main/generated/install.sh | sh -s 0.0.4
The script will install the binary into $HOME/bin
folder by default, you can override this by setting
$CUSTOM_INSTALL
environment variable
Get the archive that fits your system from the Releases page and
extract the binary into a folder that is mentioned in your $PATH
variable.
- Install kleiner and it's dependencies
- Create a new repo on github
- Clone it to make sure you have origin set up
go mod init <username>/<repo>
kleiner generate
go mod tidy
- Commit and push
- Make sure that you have
$GITHUB_TOKEN
in the environment kleiner release -tag-comment "first release"
- That's it!
For every next release just work on you changes, push them and run kleiner release
again to publish a new version
The code is inspired a lot and uses parts of the flyctl code. The files with the borrowings mention this explicitly.
Because it's a cool dutch word! It also bears some similarity with CLI acronym
I think it's useful to be able to be able to start shipping tools in the smallest possible stretch of time. Kleiner will help you to get going with no strings attached - the shared code is small, you can move it to your project and have it under your full control if you want.
Decisions are hard and to be frank most of the cli handling packages are just fine and any of them would do. You're not tied to cobra in any way, all the included commands are just tiny wrappers that can be replaced by the wrappers that use any other library.
I keep my projects on github and github gives a nice API to create releases and upload artifacts. It should be dead easy to add support for gitlab or any other service with comparable feature set.
Since all the building and packaging is done by goreleaser, you are free to build any packages it supports. The purpose of the structure generated by klein is to specifically bypass traditional packaging solutions in order to deliver instant updates.
If you want to build a cool tool for your company or your friends, you don't want to waste a week trying to build proper packages for the whole zoo of operating systems and architectures available, decide where to host repositories and so on.
The idea is to have the simplest setup possible, local setup fits this scenario
Just run kleiner generate
for your tool again and do a git diff
to check for changes. If you haven't
modified any files generated by kleiner previously you should be relatively safe to simply commit and
push.
Kleiner relies on convention now and by changing the names you'll break install and update logic. One day this part will be made configurable and then you can have your nice filenames. If you really want to have them now, just copy and modify kleiner code, it's not much.
- Windows support
- Dependencies check (goreleaser, go)
- Make it possible to generate scaffolding for other git hostings
- Much better validation and error checking
- Kleiner itself! Scaffolding was based on initial project code and releases are done with kleiner
Apache 2.0