Skip to content

Commit b63b5c6

Browse files
committed
Merge branch 'master' of https://github.com/PS-Services/Snippets
2 parents ba045a4 + cbdda0b commit b63b5c6

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

SnippetsManager.psm1

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,53 @@ class AptManager : PackageManager {
569569
return $null
570570
}
571571
}
572+
class ZypperManager : PackageManager {
573+
ZypperManager() : base(
574+
'zypper', 'zypper', 'search', 'install',
575+
'upgrade', 'update', 'search', 'remove', 'info', $true
576+
) {
577+
}
578+
579+
[Object[]]AddParameters([string]$Command, [Switch]$Global, [Object[]]$params) {
580+
if ($Command -imatch 'list|info') {
581+
return $params
582+
}
583+
584+
return $params + '-y'
585+
}
586+
587+
[ResultItem]ParseResultItem([string]$Line, [string]$Command, [Switch]$Global) {
588+
# golang-github-sahilm-fuzzy-dev/stable,oldstable,testing 0.1.0-1.1 all
589+
$regex = [Regex]::new('^ \|\s([^\s]+)\s+\|([^|]+)\|')
590+
switch -regex ($Command){
591+
'list' {
592+
$regex = [Regex]::new('^i.\s\|\s([^\s]+)\s+\|([^|]+)\|')
593+
}
594+
}
595+
$ver=$null
596+
if ($regex.IsMatch($line)) {
597+
$id = $regex.Match($line).Groups[1].Value.Trim()
598+
#$ver = $regex.Match($line).Groups[2].Value.Trim()
599+
$desc = $regex.Match($line).Groups[2].Value.Trim()
600+
$nme = $id
601+
$inst = ''
602+
switch -regex ($Command) {
603+
'search' {
604+
$inst = "$($this.Install) $id # $desc"
605+
}
606+
'list' {
607+
$inst = "$($this.Uninstall) $id # $desc"
608+
}
609+
}
610+
611+
return [ResultItem]::new(
612+
"sudo $($this.Executable)", $id, $ver, $nme, $inst, $desc, $this, $Line
613+
)
614+
}
615+
616+
return $null
617+
}
618+
}
572619

573620
class HomebrewManager : PackageManager {
574621
[string]$Store = 'main'
@@ -1250,9 +1297,12 @@ function Invoke-Any {
12501297
[PackageManager]$manager = $null
12511298

12521299
Switch -regex ($alias) {
1253-
('ap') {
1300+
('ap') {
12541301
$manager = [AptManager]::new()
12551302
}
1303+
('zy') {
1304+
$manager = [ZypperManager]::new()
1305+
}
12561306
('br') {
12571307
$manager = [HomebrewManager]::new()
12581308
}
@@ -1355,6 +1405,7 @@ if ($env:IsWindows -eq 'false') {
13551405

13561406
$results = @()
13571407
$aptResults = Invoke-Any $Command $Name -AllRepos -Raw:$Raw -Describe:$Describe -Exact:$Exact -Install:$Install -Global:$Global -managerCode 'ap'
1408+
$zypperResults = Invoke-Any $Command $Name -AllRepos -Raw:$Raw -Describe:$Describe -Exact:$Exact -Install:$Install -Global:$Global -managerCode 'zy'
13581409
$brewResults = Invoke-Any $Command $Name -Subcommand $Subcommand -AllRepos -Raw:$Raw -Describe:$Describe -Exact:$Exact -Install:$Install -Global:$Global -managerCode 'br'
13591410
$snapResults = Invoke-Any $Command $Name -Subcommand $Subcommand -AllRepos -Raw:$Raw -Describe:$Describe -Exact:$Exact -Install:$Install -Global:$Global -managerCode 'sn'
13601411

@@ -1366,6 +1417,13 @@ if ($env:IsWindows -eq 'false') {
13661417
$results.Add($aptResults)
13671418
}
13681419

1420+
if ($zypperResults -is [ResultItem[]] -or $zypperResults -is [Object[]]) {
1421+
$results.AddRange($zypperResults)
1422+
}
1423+
else {
1424+
$results.Add($zypperResults)
1425+
}
1426+
13691427
if ($brewResults -is [ResultItem[]] -or $brewResults -is [Object[]]) {
13701428
$results.AddRange($brewResults)
13711429
}
@@ -1410,7 +1468,8 @@ if ($env:IsWindows -eq 'false') {
14101468
Export-ModuleMember -Function Invoke-AllLinux
14111469

14121470
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] apt' -Name ap -Value Invoke-Any -PassThru
1413-
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] homebreq' -Name br -Value Invoke-Any -PassThru
1471+
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] zypper' -Name zy -Value Invoke-Any -PassThru
1472+
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] homebrew' -Name br -Value Invoke-Any -PassThru
14141473
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] snap' -Name sn -Value Invoke-Any -PassThru
14151474
Set-Alias -Verbose:$Verbose -Scope Global -Description 'Snippets: [repos] All Repos' -Name repos -Value Invoke-AllLinux -PassThru
14161475

0 commit comments

Comments
 (0)