| Crates.io | cbtr |
| lib.rs | cbtr |
| version | 0.3.0 |
| created_at | 2023-02-25 00:07:09.932486+00 |
| updated_at | 2025-02-22 00:59:26.897143+00 |
| description | Check, build, test, run |
| homepage | https://github.com/adam-gaia/cbtr |
| repository | https://github.com/adam-gaia/cbtr |
| max_upload_size | |
| id | 794007 |
| size | 173,034 |
Check Build Test Run
As a developer, I run commands like cargo build, docker build, poetry run, etc all the time. Basically, it's all variations of <tool> format|check|build|test|run, maybe with an extra flag here and there.
I noticed this pattern and started to write makefiles with .phony targets and then my workflow became
make build; make test; make run. With some of my projects using justfiles instead of make files, I now had two new tools repeating the same pattern of <tool> format|check|build|test|run.
That's a lot of keystrokes over time.
I started to use some shell aliases alias b='just build'; alias t='just test'; alias r='just run', which worked great until I had to work with a project without a justfile.
Muscle memory can be a double edged sword.
$ b
error: No justfile found
$ fsck
^C
$ cargo build
I realized I wanted a smarter alias that would enact the appropriate tool depending on the context.
just buildcargo buildpoetry buildAt some point along the way I added c because I run cargo check a fair amount.
This became cbtr for Check, Build, Test Run.
cbtr also supports f for commands like cargo fmt, but I had already settled on the name 'cbtr' when I added 'f' ¯\(ツ)/¯.
This crate provides binary called cbtr. Running cbtr <command>, as you might have noticed, is yet another <tool> <command> for our toolbox. But, cbtr is a
a multicall binary.
Instead of running cbtr directly, hard/symlink the binary to 'f', 'c', 'b', 't', and 'r' and run those instead.
$ ln -s ~/.local/bin/f ./cbtr
$ ln -s ~/.local/bin/c ./cbtr
$ ln -s ~/.local/bin/b ./cbtr
$ ln -s ~/.local/bin/t ./cbtr
$ ln -s ~/.local/bin/r ./cbtr
These links are called "applets", a term from busybox, the most widely known multicall program.
Now, running b invokes cbtr b, saving us the painstaking process of typing out 'cbtr ' each time. Think of the keystroke savings!
(Fyi: you can also make aliases (e.g alias b='cbtr b') if you prefer. I like the multicall applets because it's shell agnostic and I tend to switch between zsh and nushell).
All that is left now is to create a config file.
cbtr rules are defined in a toml file at ${XDG_CONFIG_HOME}/cbtr/config.toml.
The config file is an array of "entries", where each entry defines a set of tools to be ran based on some conditions.
A repo may also contain a config file in the repo root (directory containing the .git dir). The repo-level configuration will be checked first and then the user-level config will be fallen back on.
Here is an example entry with the general concepts outlined. More in-dept explnation will follow.
[[entry]]
name = "rust"
bin = "cargo" # These rules only apply if 'cargo' is found on the $PATH
file.name = "Cargo.toml" # These rules only apply if a 'Cargo.toml' exists in the repo
file.search-direction = "backwards" # Search from CWD backwards to the repo root
tools.format = "cargo fmt" # 'f' will become a shortcut for 'cargo fmt'
tools.build = "cargo build" # b -> cargo build
tools.test = "cargo test" # t -> cargo test
tools.run = "cargo run" # r -> cargo run
tools.check = ["cargo check", "cargo clippy"] # Multiple tools may be ran, in the specified order. If any fail, the rest will not be ran
There are two types of conditions
The order of the entries in the config file matters. The conditions are checked from top to bottom and the first matching entry's tool is used. If the conditions for a particular entry are met, but that entry doesn't define a tool for the invoked applet, the next matching entry (with the appropriate tool defined) will be used.
The config I use daily is included in the repo as an example: config.toml.
None of this is guarentted, but I have a few thoughts on possible directions.
tool.check to tool.c and allow for tool.[a-z].b --all -> cargo build --allPlease open an issue if any of these (or something else??) appeals to you and I'll try to prioritize it!
cbtr was originally inspired by a project called 't-for-test'. As the name implies, t-for-test provided a binary called t that acted as a shortcut for running commands like cargo test, pytest, etc.
Later t-for-test was renamed to 'project-do' and expanded to support for b and r shortcuts. My issue with project-do is that all the commands wrapped by project-do were all hard-coded.
I wanted more flexibility with a configuration scheme which lead me to develop cbtr.
Unfortunately, I can't find a link to project-do. If someone knows where to find it, please let me know! It's been a few years now, so maybe it's more flexible.