-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNovaCliHelpRequest.ps1
More file actions
85 lines (68 loc) · 2.53 KB
/
Copy pathGetNovaCliHelpRequest.ps1
File metadata and controls
85 lines (68 loc) · 2.53 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
function Get-NovaCliHelpUsageText {
[CmdletBinding()]
param()
return "Use 'nova --help', 'nova -h', 'nova --help <command>', 'nova -h <command>', or 'nova <command> --help'/'nova <command> -h'."
}
function Get-NovaCliResolvedHelpRequest {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Command,
[ValidateSet('Short', 'Long')][string]$View,
[ValidateSet('Root', 'Command')][string]$TargetType
)
return [pscustomobject]@{
Command = $Command
View = $View
TargetType = $TargetType
IsHelpRequest = $true
}
}
function Assert-NovaCliHelpUsageSupported {
[CmdletBinding()]
param(
[AllowEmptyCollection()][string[]]$Tokens = @()
)
Stop-NovaOperation -Message "Unsupported help usage. $( Get-NovaCliHelpUsageText )" -ErrorId 'Nova.Validation.UnsupportedCliHelpUsage' -Category InvalidArgument -TargetObject ($Tokens -join ' ')
}
function Get-NovaCliRootHelpRequest {
[CmdletBinding()]
param(
[AllowEmptyCollection()][string[]]$Arguments = @()
)
if ($Arguments.Count -eq 0) {
return Get-NovaCliResolvedHelpRequest -Command '--help' -View Short -TargetType Root
}
if ($Arguments.Count -eq 1 -and -not (Test-NovaCliHelpToken -Argument $Arguments[0])) {
return Get-NovaCliResolvedHelpRequest -Command $Arguments[0] -View Long -TargetType Command
}
Assert-NovaCliHelpUsageSupported -Tokens (@('--help') + $Arguments)
}
function Get-NovaCliSubcommandHelpRequest {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Command,
[AllowEmptyCollection()][string[]]$Arguments = @()
)
if ($Arguments.Count -eq 0) {
return $null
}
if ($Arguments.Count -eq 1 -and (Test-NovaCliHelpToken -Argument $Arguments[0])) {
return Get-NovaCliResolvedHelpRequest -Command $Command -View Short -TargetType Command
}
if (@($Arguments | Where-Object {Test-NovaCliHelpToken -Argument $_}).Count -gt 0) {
Assert-NovaCliHelpUsageSupported -Tokens (@($Command) + $Arguments)
}
return $null
}
function Get-NovaCliHelpRequest {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Command,
[AllowEmptyCollection()][string[]]$Arguments = @()
)
$normalizedCommand = Get-NovaCliNormalizedRootCommand -Command $Command
if ($normalizedCommand -eq '--help') {
return Get-NovaCliRootHelpRequest -Arguments $Arguments
}
return Get-NovaCliSubcommandHelpRequest -Command $normalizedCommand -Arguments $Arguments
}