cargo_run_bin/lib.rs
1//! Installing tooling globally when working in teams or on CI is a silly
2//! problem to manage. `cargo-run-bin` builds, caches, and executes binaries
3//! from their locked down versions in `Cargo.toml`, and allows your teams to
4//! always be running the same tooling versions.
5//!
6//! For command lines that extend cargo such as `cargo-nextest`, run-bin will
7//! create and manage cargo aliases to allow using cargo extensions without any
8//! changes to your command line scripts! `cargo-run-bin` gets out of your way,
9//! and you'll forget you're even using it!
10//!
11//! ## Usage
12//!
13//! For command line usage, see the [GitHub repo](https://github.com/dustinblackman/cargo-run-bin).
14//!
15//! `run-bin` can also be used as a library and paired nicely with your
16//! `build.rs` or any other scripts. The following example demos having `dprint`
17//! configured within `[package.metadata.bin]`, and executing `dprint --help`.
18//!
19//! ```toml
20//! [package.metadata.bin]
21//! dprint = { version = "0.40.2" }
22//! ```
23//!
24//! ```rust
25//! use anyhow::Result;
26//! use cargo_run_bin::{binary, metadata};
27//!
28//! fn main() -> Result<()> {
29//! let binary_package = metadata::get_binary_packages()?
30//! .iter()
31//! .find(|e| e.package == "dprint")
32//! .unwrap()
33//! .to_owned();
34//! let bin_path = binary::install(binary_package)?;
35//! binary::run(bin_path, vec!["--help".to_string()])?;
36//!
37//! return Ok(());
38//! }
39//! ```
40//!
41//! Using `binary::run` is optional. You can recreate it and make changes to
42//! your liking using `std::process`, with shims included!
43//!
44//! ```rust
45//! use std::process;
46//!
47//! use anyhow::Result;
48//! use cargo_run_bin::{binary, metadata, shims};
49//!
50//! fn main() -> Result<()> {
51//! let binary_package = metadata::get_binary_packages()?
52//! .iter()
53//! .find(|e| e.package == "dprint")
54//! .unwrap()
55//! .to_owned();
56//! let bin_path = binary::install(binary_package)?;
57//!
58//! let mut shell_paths = shims::get_shim_paths()?;
59//! shell_paths.push(env::var("PATH").unwrap_or("".to_string()));
60//!
61//! process::Command::new(bin_path)
62//! .args(["--help"])
63//! .env("PATH", shell_paths.join(":"))
64//! .spawn();
65//!
66//! return Ok(());
67//! }
68//! ```
69
70#![deny(clippy::implicit_return)]
71#![allow(clippy::needless_return)]
72
73pub mod binary;
74pub mod cargo_config;
75#[cfg(not(doc))]
76#[cfg(feature = "cli")]
77pub mod cli;
78pub mod metadata;
79pub mod shims;