Skip .NET when dotnet tool list is not successful (#302)
This commit is contained in:
@@ -488,34 +488,43 @@ pub fn run_composer_update(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||||
let dotnet = utils::require("dotnet")?;
|
let dotnet = utils::require("dotnet")?;
|
||||||
|
|
||||||
let dotnet_help_output = ctx.run_type().execute(&dotnet).arg("-h").output_checked_utf8().unwrap();
|
//Skip when the `dotnet tool list` subcommand fails. (This is expected when a dotnet runtime is installed but no SDK.)
|
||||||
|
let output = match ctx
|
||||||
if dotnet_help_output.to_string().contains("tool") {
|
.run_type()
|
||||||
let output = Command::new(dotnet)
|
.execute(&dotnet)
|
||||||
.args(["tool", "list", "--global"])
|
.args(["tool", "list", "--global"])
|
||||||
.output_checked_utf8()?;
|
.output_checked_utf8()
|
||||||
|
{
|
||||||
if !output.stdout.starts_with("Package Id") {
|
Ok(output) => output,
|
||||||
return Err(SkipStep(String::from("dotnet did not output packages")).into());
|
Err(_) => {
|
||||||
|
return Err(SkipStep(String::from(
|
||||||
|
"Error running `dotnet tool list`. This is expected when a dotnet runtime is installed but no SDK.",
|
||||||
|
))
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut packages = output.stdout.lines().skip(2).filter(|line| !line.is_empty()).peekable();
|
if !output.stdout.starts_with("Package Id") {
|
||||||
|
return Err(SkipStep(String::from("dotnet did not output packages")).into());
|
||||||
if packages.peek().is_none() {
|
|
||||||
return Err(SkipStep(String::from("No dotnet global tools installed")).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
print_separator(".NET");
|
|
||||||
|
|
||||||
for package in packages {
|
|
||||||
let package_name = package.split_whitespace().next().unwrap();
|
|
||||||
ctx.run_type()
|
|
||||||
.execute("dotnet")
|
|
||||||
.args(["tool", "update", package_name, "--global"])
|
|
||||||
.status_checked()
|
|
||||||
.with_context(|| format!("Failed to update .NET package {package_name}"))?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut packages = output.stdout.lines().skip(2).filter(|line| !line.is_empty()).peekable();
|
||||||
|
|
||||||
|
if packages.peek().is_none() {
|
||||||
|
return Err(SkipStep(String::from("No dotnet global tools installed")).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
print_separator(".NET");
|
||||||
|
|
||||||
|
for package in packages {
|
||||||
|
let package_name = package.split_whitespace().next().unwrap();
|
||||||
|
ctx.run_type()
|
||||||
|
.execute(&dotnet)
|
||||||
|
.args(["tool", "update", package_name, "--global"])
|
||||||
|
.status_checked()
|
||||||
|
.with_context(|| format!("Failed to update .NET package {package_name}"))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user