Skip to content

Commit

Permalink
Add wildcard support to Update-Package
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasNieto committed Mar 25, 2024
1 parent 3f31b04 commit 6e8871f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"cuda",
"Nieto",
"powerprepare"
"powerprepare",
"Runspace"
]
}
22 changes: 20 additions & 2 deletions src/code/ToolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Management.Automation;
using System.Text.RegularExpressions;

namespace AnyPackage.Provider.DotNet
Expand Down Expand Up @@ -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<PackageInfo>();

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)
{
Expand Down

0 comments on commit 6e8871f

Please sign in to comment.