- HTML 56.8%
- Rust 23.4%
- Shell 14.3%
- Just 5.5%
✅ has-rs
This is a Rust port of the has shell script (hereby referred to as has-bash) that checks if common tools are installed.
Specifically, it is a port made to be as close to the original bash source as possible (and as is reasonable) to make keeping up to date with new functionality as easy as possible.
Installation:
cargo install --git https://codeberg.org/cat-dev-null/has-rs
Or if you would like to specify one of the features:
# Disables the new `--allow-unsafe` flag, making has-rs act more in line with has-bash
cargo install --git https://codeberg.org/cat-dev-null/has-rs --no-default-features
# OR
# To never have to set the HAS_ALLOW_UNSAFE environment variable
cargo install --git https://codeberg.org/cat-dev-null/has-rs --no-default-features --features always-allow-unsafe
Ideally this is a drop in replacement, but here is what I can confirm are the same as of has-bash 1.5.2.
-qflag to silence output-h/--helpflag to output help- Color flags behave the same (
--color-auto,--color-always,--color-never) - Returns the number of missing programs as the exit code
- Maxes out at 126 just like has-bash
- Prints same output format
- Auto-detects and checks
.hasrcin the working directory- Comments are supported in the same way as has-bash (lines starting with
#)
- Comments are supported in the same way as has-bash (lines starting with
- Setting the HAS_ALLOW_UNSAFE environment variable to
yattempts to use--versionfor programs unknown by has-rs - Two pattern special cases act the same (
*coreutilsandlinux*utils)
Differences from the bash version
- The help output will look different
-qflag also has the long form--quiet-v/--versionflag outputs the version, but in the Rust clap standard format- has-rs:
has 0.2.3 - has-bash:
v1.5.2
- has-rs:
- .hasrc supports comments not just as whole line but end of line (e.g.
jq # needed for tooling) - Alternates can be specified by separating with the "|" character
- For example,
has "curl|wget"will check for curl and, if it is not found, will then check for wget - It is only counted as a failure if none of the programs are present
- For example,
- Optional programs can be specified by appending a
?to the program name- For example,
has "curl?"will check for curl and, if it is not found, will not fail the check
- For example,
- The new
--hide-optionalflag will suppress output for missing alternates or optional programs- For example,
has "curl|wget"will print a line forcurlif it is not found;has "curl|wget" --hide-optionalwill not
- For example,
- The new
--no-rcflag will skip loading the .hasrc file - The new
--allow-unsafeflag acts like (and supersedes) the HAS_ALLOW_UNSAFE environment variable
has-rs can also be compiled so that "allow safe" is always allowed, which is achieved via the always-allow-unsafe feature. If this feature is enabled, allow-unsafe-flag cannot also be enabled, because there is no point to either the flag or the environment variable in that case.
Building
Whilst of course you can just use cargo build, this project uses just as a task runner.
Take a look at .hasrc (or if you have has-bash install, just run has) to see what is expected to be on your system.
Here's some helpful commands to get you started:
just --listorjust -lshows all available recipesjust buildorjustwill build for your host systemjust build-allbuilds for all platforms, architectures, and standard C librariesjust build-all-linux,just build-all-windows, andjust build-all-macall do what they sayjust testwill run the non-Rust tests that ensure the program is working as expectedjust distwill package up any binaries that have been compiled inside thedistdirectory
Why?
Some might ask, why port a perfectly good shell script to Rust?
- I hate bash
- I'm exploring Rust
- For fun