diff --git a/docs/dev-tools/backends/cargo.md b/docs/dev-tools/backends/cargo.md index 93f0bbe421..dcb1042506 100644 --- a/docs/dev-tools/backends/cargo.md +++ b/docs/dev-tools/backends/cargo.md @@ -3,7 +3,7 @@ You may install packages directly from [Cargo Crates](https://crates.io/) even if there isn't an asdf plugin for it. -The code for this is inside of the mise repository at [`./src/backend/cargo.rs`](https://github.com/jdx/mise/blob/main/src/backend/cargo.rs). +The code for this is inside the mise repository at [`./src/backend/cargo.rs`](https://github.com/jdx/mise/blob/main/src/backend/cargo.rs). ## Dependencies @@ -74,18 +74,47 @@ go in `[tools]` in `mise.toml`. ### `features` -Install additional components: +Install additional components (passed as `cargo install --features`): ```toml [tools] -"cargo:cargo-edit" = { features = "add" } +"cargo:cargo-edit" = { version = "latest", features = "add" } ``` ### `default-features` -Disable default features: +Disable default features (passed as `cargo install --no-default-features`): ```toml [tools] -"cargo:cargo-edit" = { default-features = false } +"cargo:cargo-edit" = { version = "latest", default-features = false } +``` + +### `bin` + +Select the CLI bin name to install when multiple are available (passed as `cargo install --bin`): + +```toml +[tools] +"cargo:github.com/username/demo" = { version = "tag:v1.0.0", bin = "demo" } +``` + +### `crate` + +Select the crate name to install when multiple are available (passed as +`cargo install --git= `): + +```toml +[tools] +"cargo:github.com/username/demo" = { version = "tag:v1.0.0", crate = "demo" } +``` + +### `locked` + +Use Cargo.lock (passes `cargo install --locked`) when building CLI. This is the default behavior, +pass `false` to disable: + +```toml +[tools] +"cargo:github.com/username/demo" = { version = "latest", locked = false } ``` diff --git a/src/backend/cargo.rs b/src/backend/cargo.rs index 4c28ae2b9b..2a9897784e 100644 --- a/src/backend/cargo.rs +++ b/src/backend/cargo.rs @@ -99,17 +99,28 @@ impl Backend for CargoBackend { }; let opts = tv.request.options(); + if let Some(bin) = opts.get("bin") { + cmd = cmd.arg(format!("--bin={bin}")); + } + if !opts + .get("locked") + .is_some_and(|v| v.to_lowercase() == "false") + { + cmd = cmd.arg("--locked"); + } if let Some(features) = opts.get("features") { - cmd = cmd.arg(format!("--features={}", features)); + cmd = cmd.arg(format!("--features={features}")); } if let Some(default_features) = opts.get("default-features") { if default_features.to_lowercase() == "false" { cmd = cmd.arg("--no-default-features"); } } + if let Some(c) = opts.get("crate") { + cmd = cmd.arg(c); + } - cmd.arg("--locked") - .arg("--root") + cmd.arg("--root") .arg(tv.install_path()) .with_pr(ctx.pr.as_ref()) .envs(ctx.ts.env_with_path(&config)?) diff --git a/src/cmd.rs b/src/cmd.rs index 636625f015..2d5dcf5048 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; use std::ffi::{OsStr, OsString}; -use std::fmt::{Display, Formatter}; +use std::fmt::{Debug, Display, Formatter}; use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus, Stdio}; @@ -442,6 +442,13 @@ impl Display for CmdLineRunner<'_> { } } +impl Debug for CmdLineRunner<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let args = self.get_args().join(" "); + write!(f, "{} {args}", self.get_program()) + } +} + enum ChildProcessOutput { Stdout(String), Stderr(String),