-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathTest-MBPublicFunctionName.ps1
More file actions
74 lines (67 loc) · 2.08 KB
/
Copy pathTest-MBPublicFunctionName.ps1
File metadata and controls
74 lines (67 loc) · 2.08 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
function Test-MBPublicFunctionName {
<#
.SYNOPSIS
Tests validity of a function name and path.
.DESCRIPTION
Tests validity of a function name and path.
.PARAMETER Name
Name of the function to add. Must use a valid PowerShell verb-action format and be singular.
.PARAMETER ShowIssues
Displays possible issues with function
.LINK
https://github.com/ModuleBuild/ModuleBuild
.EXAMPLE
TBD
#>
[CmdletBinding()]
param(
[parameter(Position = 0, ValueFromPipeline = $TRUE)]
[String]$Name,
[parameter(Position = 1)]
[switch]$ShowIssues
)
$FunctionOk = $TRUE
try {
$FunctionPath = Split-Path $Name
$FunctionFileName = Split-Path $Name -Leaf
$FunctionName = ($FunctionFileName -split '\.')[0]
Write-Verbose "Function Path: $FunctionPath"
Write-Verbose "Function FileName: $FunctionFileName"
Write-Verbose "Function Name: $FunctionName"
}
catch {
if ($ShowIssues) {
Write-Warning "Function path does not appear to include a path or filename: $Name"
}
$FunctionOk = $FALSE
}
if ($FunctionName -match '[^a-zA-Z\-]') {
if ($ShowIssues) {
Write-Warning "Function name has special characters: $Name"
}
$FunctionOk = $FALSE
}
if (-not $FunctionName.contains('-')) {
if ($ShowIssues) {
Write-Warning "Function name must be in a verb-noun format: $Name"
}
$FunctionOk = $FALSE
}
else {
$Verb,$Noun = $FunctionName -split '-'
$ValidVerbs = (Get-Verb).verb
if ($ValidVerbs -notcontains $Verb) {
if ($ShowIssues) {
Write-Warning "Function verb is not valid, use 'get-verb' for a list of valid verbs: $Name"
}
$FunctionOk = $FALSE
}
if (TestMBPlural $Noun) {
if ($ShowIssues) {
Write-Warning "Function noun is plural and should be singular: $Name"
}
$FunctionOk = $FALSE
}
}
return $FunctionOk
}