From 4709d4ec31a8788c48c0162a266ec06638992da5 Mon Sep 17 00:00:00 2001 From: reisir Date: Sat, 7 Oct 2023 20:53:35 +0300 Subject: [PATCH] mond install single match --- @Resources/MonD.inc | 2 +- MetersOnDemand.ps1 | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/@Resources/MonD.inc b/@Resources/MonD.inc index 3357c49..7405571 100644 --- a/@Resources/MonD.inc +++ b/@Resources/MonD.inc @@ -7,6 +7,6 @@ Description=Meters on Demand, the Rainmeter package manager SkinName=Meters on Demand LoadType=Skin Load=Meters on Demand\Installer.ini -Version=v1.2.2 +Version=v1.2.3 HeaderImage=#@#mond.bmp Exclude=cache.json | mond.log | temp diff --git a/MetersOnDemand.ps1 b/MetersOnDemand.ps1 index 339d9e4..f60cfd4 100644 --- a/MetersOnDemand.ps1 +++ b/MetersOnDemand.ps1 @@ -82,7 +82,7 @@ param ( # Globals $Self = [PSCustomObject]@{ - Version = "v1.2.2"; + Version = "v1.2.3"; Directory = "#Mond"; FileName = "MetersOnDemand.ps1"; BatFileName = "mond.bat" @@ -274,10 +274,20 @@ function Install { $Cache, [Parameter()] [switch] - $Force + $Force, + [Parameter()] + [Switch] + $FirstMatch ) if (!$Cache) { $Cache = Update-Cache } + if ($FirstMatch) { + $Matched = Search -Query $FullName -Cache $Cache -Quiet + if ($Matched.Length -gt 1) { throw "Too many results, use a more specific query" } + if ($Matched.Length -eq 0) { throw "No results" } + $FullName = $Matched[0].full_name + } + $installed = $Cache.Installed.$FullName if ($installed -and (-not $Force)) { return Write-Host "$($FullName) is already installed. Use -Force to reinstall." -ForegroundColor Yellow @@ -585,14 +595,17 @@ function Search { $Property, [Parameter(Mandatory)] [psobject] - $Cache + $Cache, + [Parameter()] + [Switch] + $Quiet ) if (!$Query) { $Query = ".*" } if (!$Property) { $Property = "full_name" } if (!$Cache) { $Cache = Update-Cache } - Write-Host "Searching for `"$Query`"" + if (!$Quiet) { Write-Host "Searching for `"$Query`"" } $Results = @() foreach ($Entry in ToIteratable -Object $Cache.Skins ) { @@ -1030,9 +1043,7 @@ function Format-SkinList { if ($Description) { Write-Host "$($_.description)" } if ($NewLine) { Write-Host "" } - } - } # Main body @@ -1067,7 +1078,7 @@ try { if (-not $Parameter) { throw "Install requires the named parameter -Skin (Position = 1)" } - Install -FullName $Parameter -Cache $Cache -Force:$Force + Install -FullName $Parameter -Cache $Cache -Force:$Force -FirstMatch break } "list" {