Repository navigation
Expand file tree
/
Copy pathRepository.psm1
More file actions
128 lines (109 loc) · 4.77 KB
/
Copy pathRepository.psm1
File metadata and controls
128 lines (109 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# FULL # BEGIN FULL: Don't include this in the installer script
$PoshCodeModuleRoot = Get-Variable PSScriptRoot -ErrorAction SilentlyContinue | ForEach-Object { $_.Value }
if(!$PoshCodeModuleRoot) {
$PoshCodeModuleRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}
. $PoshCodeModuleRoot\Constants.ps1
# FULL # END FULL
$CommonParameters = "ErrorAction", "WarningAction", "Verbose", "Debug", "ErrorVariable", "WarningVariable", "OutVariable", "OutBuffer", "PipelineVariable"
function Find-Module {
<#
.Synopsis
Find PoshCode packages online
.DESCRIPTION
This searches a list of online repositories (like github) for available modules packages.
.EXAMPLE
Find-Module
Lists all the module in all the available repositories
.EXAMPLE
Find-Module Viso
Find all modules which mention Visio in (their package manifests) in all repositories
.EXAMPLE
Find-Module -Author jrich523
Finds all modules by jrich523 in all repositories
.EXAMPLE
Find-Module -Author jrich523 -ModuleName PSVA -Repository GitHub
Finds a specific module by a specific author in a specific repository
.OUTPUTS
PoshCode.Search.ModuleInfo
#>
[CmdletBinding()]
Param
(
# Term to Search for
[string]$SearchTerm,
# Search for modules published by a particular author.
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$Author,
# Search for a specific module.
[alias('Name','MN')]
[Parameter(ValueFromPipelineByPropertyName=$true)]
[string]$ModuleName,
# The path of a configured repository (allows wildcards), or a hashtable of @{RepositoryType=@("RepositoryRootUri")}
[Parameter(ValueFromPipelineByPropertyName=$true)]
$Repository,
[int]
$Limit = 0
)
begin {
$Count = 0
}
process {
if(($Repository -is [hashtable]) -or ($Repository -as [hashtable[]])) {
$ConfiguredRepositories = $Repository
} else {
$ConfiguredRepositories = @((Get-ConfigData).Repositories)
if(!$Repository) {
$ConfiguredRepositories = $ConfiguredRepositories | Where-Object { $_.SearchByDefault }
} else {
# Filter Repositories
# $ConfiguredRepositories = @((Get-ConfigData).Repositories)
$ConfiguredRepositories = $(
$Matching = $ConfiguredRepositories | Where-Object { foreach($r in @($Repository)){ $_.Type -like "$r" } }
if(!$Matching) {
Write-Verbose "No matching Type"
$Matching = $ConfiguredRepositories | Where-Object { foreach($r in @($Repository)){ $_.Name -like "$r" } }
}
if(!$Matching) {
Write-Verbose "No matching Name"
$Matching = $ConfiguredRepositories | Where-Object { foreach($r in @($Repository)){ $_.Root -like "$r" } }
}
$Matching
)
}
}
$null = $PSBoundParameters.Remove("Repository")
$null = $PSBoundParameters.Remove("Limit")
# Write-Verbose ($ConfiguredRepositories | %{ $_ | Format-Table -HideTableHeaders }| Out-String -Width 110)
foreach($Repo in $ConfiguredRepositories) {
$Command = Import-Module "${PoshCodeModuleRoot}\Repositories\$(${Repo}.Type)" -Passthru | % { $_.ExportedCommands['FindModule'] }
Write-Verbose "$(${Repo}.Type)\FindModule -Root $($Repo.Root)"
foreach($k in @($Repo.Keys) | Where-Object { ($Command.Parameters.Keys -contains $_) -and ("Type" -notcontains $_)}) {
$PSBoundParameters.$k = $Repo.$k
}
$Mandatory = $Command.Parameters.Values |
Where-Object { $_.Attributes.Mandatory -and ($PSBoundParameters.Keys -NotContains $_.Name)} |
ForEach-Object { $_.Name }
if($Mandatory) {
Write-Warning "Not searching $($Repo.Type), missing mandatory parameter(s) '$($Mandatory -join ''',''')'"
} else {
# Write-Verbose ($PSBoundParameters | Format-Table | Out-String -Width 110)
try {
if($Limit -gt 0) {
&$Command @PSBoundParameters | Add-Member NoteProperty ModuleType SearchResult -Passthru |
ForEach-Object { if(($Count++) -lt $Limit){ $_ } else { break }
}
} else {
&$Command @PSBoundParameters | Add-Member NoteProperty ModuleType SearchResult -Passthru
}
}
catch
{
Write-Warning "Error Searching $($Repo.Type) $($Repo.Root)"
}
if($Limit -gt 0 -and $Count -ge $Limit) { return }
}
}
}
}
Export-ModuleMember -Function 'Find-Module'