-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-RubyVersion.ps1
More file actions
51 lines (44 loc) · 1.53 KB
/
Set-RubyVersion.ps1
File metadata and controls
51 lines (44 loc) · 1.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
function Set-RubyVersion {
[CmdletBinding(DefaultParameterSetName = 'Shell', SupportsShouldProcess)]
param(
[ArgumentCompleter({
param($cmd, $param, $wordToComplete)
(Get-RubyVersion -Installed).
ForEach({ $_.Version.ToString() }).
Where({ $_ -like "${wordToComplete}*" })
})]
[Parameter(Mandatory, Position = 0)]
[ValidateNotNullOrWhiteSpace()]
[string] $Version,
[Parameter(ParameterSetName = 'Shell')]
[switch] $Shell,
[Parameter(ParameterSetName = 'Local', Mandatory)]
[switch] $Local,
[Parameter(ParameterSetName = 'Global', Mandatory)]
[switch] $Global
)
$callerErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = [Management.Automation.ActionPreference]::Stop
try {
if ($PSCmdlet.ShouldProcess($PSCmdlet.ParameterSetName, "Set Ruby Version to $Version")) {
switch -Exact ($PSCmdlet.ParameterSetName) {
'Shell' {
Set-ShellRubyVersion -Version $Version
break
}
'Local' {
Set-LocalRubyVersion -Version $Version
break
}
'Global' {
Set-GlobalRubyVersion -Version $Version
break
}
}
}
}
catch {
$global:Error.RemoveAt(0)
Write-Error $_ -ErrorAction $callerErrorActionPreference
}
}