Skip to content

Commit 33a9b51

Browse files
committed
fix(installer): spinner not being suspended with tool installs
1 parent 6f9e51a commit 33a9b51

2 files changed

Lines changed: 53 additions & 68 deletions

File tree

784 Bytes
Binary file not shown.

installer/src/installers/installer.rs

Lines changed: 53 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,9 @@ impl Installer {
161161
continue;
162162
}
163163

164-
if !Command::new(&cargo_command)
165-
.args(["install", tool.package.as_str()])
166-
.status()?
167-
.success()
168-
{
164+
let mut command = Command::new(&cargo_command);
165+
command.args(["install", tool.package.as_str()]);
166+
if !self.command_succeeded(&mut command)? {
169167
return Err(anyhow::anyhow!(
170168
"Failed to install Cargo package {}",
171169
tool.package
@@ -178,11 +176,9 @@ impl Installer {
178176
continue;
179177
}
180178

181-
if !Command::new("go")
182-
.args(["install", tool.package.as_str()])
183-
.status()?
184-
.success()
185-
{
179+
let mut command = Command::new("go");
180+
command.args(["install", tool.package.as_str()]);
181+
if !self.command_succeeded(&mut command)? {
186182
return Err(anyhow::anyhow!(
187183
"Failed to install Go package {}",
188184
tool.package
@@ -199,26 +195,22 @@ impl Installer {
199195
"functions -q nvm; and nvm use default --silent; and npm install -g '{}'",
200196
tool.package
201197
);
202-
if !Command::new("fish")
203-
.args(["-c", command.as_str()])
204-
.status()?
205-
.success()
206-
{
198+
let mut npm_command = Command::new("fish");
199+
npm_command.args(["-c", command.as_str()]);
200+
if !self.command_succeeded(&mut npm_command)? {
207201
return Err(anyhow::anyhow!(
208202
"Failed to install npm package {}",
209203
tool.package
210204
));
211205
}
212206
}
213207

214-
if self.packages.uv.install_uv
215-
&& which("uv").is_err()
216-
&& !Command::new("sh")
217-
.args(["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"])
218-
.status()?
219-
.success()
220-
{
221-
return Err(anyhow::anyhow!("Failed to install uv"));
208+
if self.packages.uv.install_uv && which("uv").is_err() {
209+
let mut command = Command::new("sh");
210+
command.args(["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"]);
211+
if !self.command_succeeded(&mut command)? {
212+
return Err(anyhow::anyhow!("Failed to install uv"));
213+
}
222214
}
223215

224216
let uv_command = which("uv")
@@ -230,11 +222,9 @@ impl Installer {
230222
continue;
231223
}
232224

233-
if !Command::new(&uv_command)
234-
.args(["tool", "install", tool.package.as_str()])
235-
.status()?
236-
.success()
237-
{
225+
let mut command = Command::new(&uv_command);
226+
command.args(["tool", "install", tool.package.as_str()]);
227+
if !self.command_succeeded(&mut command)? {
238228
return Err(anyhow::anyhow!(
239229
"Failed to install uv package {}",
240230
tool.package
@@ -251,26 +241,22 @@ impl Installer {
251241
return Ok(());
252242
}
253243

254-
if !Command::new("fish")
255-
.args([
256-
"-c",
257-
"functions -q fisher; or begin; curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source; fisher install jorgebucaran/fisher; end",
258-
])
259-
.status()?
260-
.success()
261-
{
244+
let mut command = Command::new("fish");
245+
command.args([
246+
"-c",
247+
"functions -q fisher; or begin; curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source; fisher install jorgebucaran/fisher; end",
248+
]);
249+
if !self.command_succeeded(&mut command)? {
262250
return Err(anyhow::anyhow!("Failed to install Fisher"));
263251
}
264252

265253
for plugin in &self.packages.fish.plugins {
266254
let command = format!(
267255
"fisher list | string match -q -- '{plugin}'; or fisher install '{plugin}'"
268256
);
269-
if !Command::new("fish")
270-
.args(["-c", command.as_str()])
271-
.status()?
272-
.success()
273-
{
257+
let mut fish_command = Command::new("fish");
258+
fish_command.args(["-c", command.as_str()]);
259+
if !self.command_succeeded(&mut fish_command)? {
274260
return Err(anyhow::anyhow!("Failed to install Fish plugin {plugin}"));
275261
}
276262
}
@@ -279,36 +265,31 @@ impl Installer {
279265
}
280266

281267
fn install_node_tools(&self) -> anyhow::Result<()> {
282-
if self.packages.node.install_default_lts
283-
&& !Command::new("fish")
284-
.args([
285-
"-c",
286-
"functions -q nvm; and nvm install lts; and set --universal nvm_default_version lts",
287-
])
288-
.status()?
289-
.success()
290-
{
291-
return Err(anyhow::anyhow!("Failed to install default Node.js LTS"));
268+
if self.packages.node.install_default_lts {
269+
let mut command = Command::new("fish");
270+
command.args([
271+
"-c",
272+
"functions -q nvm; and nvm install lts; and set --universal nvm_default_version lts",
273+
]);
274+
if !self.command_succeeded(&mut command)? {
275+
return Err(anyhow::anyhow!("Failed to install default Node.js LTS"));
276+
}
292277
}
293278

294-
if self.packages.node.install_bun
295-
&& which("bun").is_err()
296-
&& !Command::new("sh")
297-
.args(["-c", "curl -fsSL https://bun.sh/install | bash"])
298-
.status()?
299-
.success()
300-
{
301-
return Err(anyhow::anyhow!("Failed to install Bun"));
279+
if self.packages.node.install_bun && which("bun").is_err() {
280+
let mut command = Command::new("sh");
281+
command.args(["-c", "curl -fsSL https://bun.sh/install | bash"]);
282+
if !self.command_succeeded(&mut command)? {
283+
return Err(anyhow::anyhow!("Failed to install Bun"));
284+
}
302285
}
303286

304-
if self.packages.node.install_pnpm
305-
&& which("pnpm").is_err()
306-
&& !Command::new("sh")
307-
.args(["-c", "curl -fsSL https://get.pnpm.io/install.sh | sh -"])
308-
.status()?
309-
.success()
310-
{
311-
return Err(anyhow::anyhow!("Failed to install pnpm"));
287+
if self.packages.node.install_pnpm && which("pnpm").is_err() {
288+
let mut command = Command::new("sh");
289+
command.args(["-c", "curl -fsSL https://get.pnpm.io/install.sh | sh -"]);
290+
if !self.command_succeeded(&mut command)? {
291+
return Err(anyhow::anyhow!("Failed to install pnpm"));
292+
}
312293
}
313294

314295
Ok(())
@@ -334,11 +315,15 @@ impl Installer {
334315
for command in commands {
335316
let mut cmd = Command::new(&command[0]);
336317
cmd.args(&command[1..]);
337-
if !self.spinner.suspend(|| cmd.status())?.success() {
318+
if !self.command_succeeded(&mut cmd)? {
338319
return Err(anyhow::anyhow!("Failed to run command: {:?}", command));
339320
}
340321
}
341322

342323
Ok(())
343324
}
325+
326+
fn command_succeeded(&self, command: &mut Command) -> anyhow::Result<bool> {
327+
Ok(self.spinner.suspend(|| command.status())?.success())
328+
}
344329
}

0 commit comments

Comments
 (0)