From 6e8871ff64e4ae3f3aeaabba06c5885dc6f779b9 Mon Sep 17 00:00:00 2001 From: Thomas Nieto <38873752+ThomasNieto@users.noreply.github.com> Date: Sun, 24 Mar 2024 19:21:35 -0500 Subject: [PATCH] Add wildcard support to Update-Package --- .vscode/settings.json | 3 ++- src/code/ToolProvider.cs | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 53b7c01..3fac48a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "cuda", "Nieto", - "powerprepare" + "powerprepare", + "Runspace" ] } \ No newline at end of file diff --git a/src/code/ToolProvider.cs b/src/code/ToolProvider.cs index 5745ce2..c1e8357 100644 --- a/src/code/ToolProvider.cs +++ b/src/code/ToolProvider.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Management.Automation; using System.Text.RegularExpressions; namespace AnyPackage.Provider.DotNet @@ -168,8 +169,25 @@ public void UninstallPackage(PackageRequest request) public void UpdatePackage(PackageRequest request) { - //TODO: Support wildcard - var args = $"tool update {request.Name} --global"; + using var powershell = PowerShell.Create(RunspaceMode.CurrentRunspace); + + var packages = powershell.AddCommand("Get-Package") + .AddParameter("Provider", ".NET Tool") + .AddCommand("Where-Object") + .AddParameter("Property", "Name") + .AddParameter("Like") + .AddParameter("Value", request.Name) + .Invoke(); + + foreach (var package in packages) + { + InvokeUpdate(request, package.Name); + } + } + + private void InvokeUpdate(PackageRequest request, string name) + { + var args = $"tool update {name} --global"; if (request.Version is not null) {