mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-28 13:20:41 +00:00
fix: 🐛 Check if a crate is installed before triying to install it
This commit is contained in:
parent
253ef013e4
commit
f700e92820
@ -154,72 +154,108 @@ pub struct RustCrate {
|
||||
impl RustCrate {
|
||||
/// Installs a crate.
|
||||
pub fn install(&self) -> Result<()> {
|
||||
cmd!("cargo", "install", "cargo-binstall").run()?;
|
||||
info!("{} Installing {} crate", emoji::WRENCH, self.name);
|
||||
if let Some(binstall) = &self.binstall {
|
||||
cmd!(
|
||||
"cargo",
|
||||
"binstall",
|
||||
"--no-confirm",
|
||||
"--pkg-url",
|
||||
&binstall.url,
|
||||
"--pkg-fmt",
|
||||
&binstall.fmt,
|
||||
"--bin-dir",
|
||||
&binstall.bin,
|
||||
&self.name
|
||||
)
|
||||
.run()?;
|
||||
let output = cmd!("cargo", "install", "--list").stdout()?;
|
||||
if output.contains(&self.name) {
|
||||
warn!("{} {} is already installed", emoji::WARN, self.name);
|
||||
Ok(())
|
||||
} else {
|
||||
cmd!("cargo", "install", &self.name).run()?;
|
||||
info!("{} Installing {} crate", emoji::WRENCH, self.name);
|
||||
if let Some(binstall) = &self.binstall {
|
||||
// TODO: Fix this as is not picking the arguments properly
|
||||
if !output.contains("cargo-binstall") {
|
||||
info!("{} Installing cargo-binstall crate", emoji::WRENCH);
|
||||
cmd!("cargo", "install", "cargo-binstall").run()?;
|
||||
}
|
||||
println!(
|
||||
"cargo binstall --no-confirm --pkg-url {} --pkg-fmt {} --bin-dir {}",
|
||||
binstall.url, binstall.fmt, binstall.bin
|
||||
);
|
||||
cmd!(
|
||||
"cargo",
|
||||
"binstall",
|
||||
"--no-confirm",
|
||||
"--pkg-url",
|
||||
&binstall.url,
|
||||
"--pkg-fmt",
|
||||
&binstall.fmt,
|
||||
"--bin-dir",
|
||||
&binstall.bin,
|
||||
&self.name
|
||||
)
|
||||
.run()?;
|
||||
} else {
|
||||
cmd!("cargo", "install", &self.name).run()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a crate instance.
|
||||
pub fn new(name: &str) -> Self {
|
||||
match name {
|
||||
// "ldproxy" => {
|
||||
// RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }.{ archive-format }".to_string(),
|
||||
// bin: "{ bin }{ binary-ext }".to_string(),
|
||||
// fmt: "zip".to_string(),
|
||||
// }),
|
||||
// }
|
||||
// }
|
||||
// "espflash" => {
|
||||
// RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }.{ archive-format }".to_string(),
|
||||
// bin: "{ bin }{ binary-ext }".to_string(),
|
||||
// fmt: "zip".to_string(),
|
||||
// }),
|
||||
// }
|
||||
// }
|
||||
"cargo-generate" => {
|
||||
RustCrate {
|
||||
name: name.to_string() + "@0.15.2",
|
||||
binstall: Some(BinstallCrate {
|
||||
url: "{ repo }/releases/download/v{ version }/{ name}-{ version }-{ target }.{ archive-format }".to_string(),
|
||||
bin: "{ bin }{ binary-ext }".to_string(),
|
||||
fmt: "tgz".to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
// "wokwi-server" => {
|
||||
|
||||
// },
|
||||
// "web-flash" => {
|
||||
|
||||
// },
|
||||
_ => RustCrate {
|
||||
name: name.to_string(),
|
||||
binstall: None,
|
||||
},
|
||||
RustCrate {
|
||||
name: name.to_string(),
|
||||
binstall: None,
|
||||
}
|
||||
// match name {
|
||||
// "ldproxy" => {
|
||||
// RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }.{ archive-format }".to_string(),
|
||||
// bin: "{ bin }{ binary-ext }".to_string(),
|
||||
// fmt: "zip".to_string(),
|
||||
// }),
|
||||
// }
|
||||
// }
|
||||
// "espflash" => {
|
||||
// RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }.{ archive-format }".to_string(),
|
||||
// bin: "{ bin }{ binary-ext }".to_string(),
|
||||
// fmt: "zip".to_string(),
|
||||
// }),
|
||||
// }
|
||||
// }
|
||||
// "cargo-generate" => {
|
||||
// RustCrate {
|
||||
// name: name.to_string() + "@0.15.2",
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "{ repo }/releases/download/v{ version }/{ name }-{ version }-{ target }.{ archive-format }".to_string(),
|
||||
// bin: "{ bin }{ binary-ext }".to_string(),
|
||||
// fmt: "tgz".to_string(),
|
||||
// }),
|
||||
// }
|
||||
// }
|
||||
// "sccache" => RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "".to_string(),
|
||||
// bin: "".to_string(),
|
||||
// fmt: "".to_string(),
|
||||
// }),
|
||||
// },
|
||||
// "wokwi-server" => RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "".to_string(),
|
||||
// bin: "".to_string(),
|
||||
// fmt: "".to_string(),
|
||||
// }),
|
||||
// },
|
||||
// "web-flash" => RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: Some(BinstallCrate {
|
||||
// url: "".to_string(),
|
||||
// bin: "".to_string(),
|
||||
// fmt: "".to_string(),
|
||||
// }),
|
||||
// },
|
||||
// _ => RustCrate {
|
||||
// name: name.to_string(),
|
||||
// binstall: None,
|
||||
// },
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user