crp

Crates.iocrp
lib.rscrp
version0.2.2
created_at2025-09-14 12:21:01.66048+00
updated_at2025-09-15 17:15:20.935089+00
descriptionUtility to shorten and streamline workspace member execution
homepage
repositoryhttps://codeberg.org/petervaro/crp
max_upload_size
id1838682
size48,017
Peter Varo (petervaro)

documentation

README

crp

status-badge

In a large Cargo workspace a lot of automation is likely to be expressed in the form of Rust scripts. Some of the great advantages of this is that these are written in the same language as the rest of the code base, can reuse any entities of it, and work particularly well across multiple operating systems and architectures. The downside is that they need to be compiled on each invocation from scratch to make sure the executed program is the latest—or at least checked whether anything has changed in it or its dependencies. Thus, these are invoked with cargo run, explicitly specifying the package to be executed and all of its arguments passed down.

That might require a lot of typing and longer commands than necessary. And that is precisely what crp solves, it shortens the command and makes it more convenient to use and to remember.

How Does It Work?

crp takes the first argument and passes that down to a cargo run invocation as the --package. The rest of the arguments are passed down as options to the running package itself.

# This `crp` invocation:
$ crp <package> <arguments>...
# Is the same as:
$ cargo run --package <package> -- <arguments>...

Installation

The simplest and most flexible way to install crp is with cargo:

$ cargo install crp

N.B. Installing crp like this leads to the leanest and fastest execution, however, further configuration options are available at build time which alter its behaviour. These are detailed in the following sections.

Customisation

If there's a common prefix and/or suffix in your project(s), crp can take care of adding those before or after the passed down package name, allowing further shortening of the command. This can be particularly useful when combined with per directory customisation with the likes of direnv.

To enable any of these abilities, crp should be compiled with specific features as listed below:

Feature Environment Variables Functionality
prefix-handling CRP_PACKAGE_PREFIX Prefix to be added before the package name
suffix-handling CRP_PACKAGE_SUFFIX Suffix to be added after the package name
$ cargo install crp --features prefix-handling,suffix-handling

Example

In an imaginary workspace where all tasks are prefixed with script-, the fictional script-upload task can be invoked as such:

$ export CRP_PACKAGE_PREFIX='script-'

# This `crp` invocation:
$ crp upload --timeout 10s
# Is the same as:
$ cargo run --package script-upload -- --timeout 10s

Escaping

When crp installed with any of the affix handling enabled, it is capable of handling an optional short flag, -e (stands for 'without environment'), which allows ignoring the CRP_* environment variables.

In an imaginary workspace where both download and download-task crates are available the following invocations can be made:

export CRP_PACKAGE_SUFFIX='-task'

# This `crp` invocation:
$ crp download --url https://example.com
# Is the same as:
$ cargo run --package download-task -- --url https://example.com

# And this `crp` invocation:
$ crp -e download --url https://example.com
# Is the same as:
$ cargo run --package download -- --url https://example.com

Why Is It Called crp?

  1. It is not a widely used command name and therefore it won't accidentally collide with anything, based on Arch Linux manual pages query at the time of choosing the project's name.
  2. It stands for cargo run package, which is (somewhat) self-explanatory.
  3. It is available as a crate name.

Alternatives

  • cargo-xtask: It is not an extension to Cargo, but a pattern. As such, it has the advantage that no installation is required, it works out of the box with cargo. In a way, crp is an additional layer to xtask, but instead of cargo xtask the invocation becomes crp xtask and therefore no extra aliasing is required.

    That being said, the two has different purposes, xtask unifies the task execution into a single entry-point, whereas crp simplifies the invocation of running a particular package of a workspace, therefore, the two are not mutually exclusive, nor they are alternatives to one another.

License

Copyright ©2025 Peter Varo

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses.

Commit count: 0

cargo fmt