pub fn cargo(progress_message: impl Into<String>) -> Cargojson and print and process only.Expand description
Display progress of cargo task with a progress bar, and emitting status messages and diagnostic messages using this crate’s printing utilities.
json feature is required to enable parsing cargo’s output messages.
use cu::pre::*;
cu::which("cargo")?.command()
.args(["build", "--release"])
.preset(cu::pio::cargo("building my crate"))
.spawn()?.0
.wait_nz()?;§Behavior
- Added args:
--message-format json-diagnostic-rendered-ansi - All IO will be configured. You should avoid configuring IO by yourself before or after applying this preset. This may become enforced in the future through generics.
The progress is displayed on the progress bar, showing the current crates being built in one line (similar to the build progress bar shown by cargo).
You can customize the spawned progress bar with
§Message levels
Errors, warnings and status messages (like Compiling foobar v0.1.0)
can be configured with the error, warning,
or other functions that take a message level.
use cu::pre::*;
cu::pio::cargo("cargo build")
// configure message levels; levels shown here are the default
.error(cu::lv::E)
.warning(cu::lv::W)
.other(cu::lv::D);§Diagnostic hooks
To process diagnostic messages from cargo, you can provide a diagnostic hook,
which is a function (is_warning: bool, message: &str) -> ().
If a diagnostic hook is provided, then the hook is responsible for displaying
the message. The error and warning levels will have no effect.
use cu::pre::*;
cu::pio::cargo("cargo build")
// configure message levels; levels shown here are the default
.on_diagnostic(|is_warning, message| {
// this implementation will be identical to the default behavior
if is_warning {
cu::warn!("{message}")
} else {
cu::error!("{message}")
}
});§Output
The handle to the progress bar is emitted to the stdout slot.
Be sure to manually call .done() on it. See Progress Bars
for more details