|
1 | 1 | #Requires -Version 5
|
2 |
| -param($cmd) |
| 2 | +param($SubCommand) |
3 | 3 |
|
4 |
| -Set-StrictMode -off |
| 4 | +Set-StrictMode -Off |
5 | 5 |
|
6 | 6 | . "$PSScriptRoot\..\lib\core.ps1"
|
7 | 7 | . "$PSScriptRoot\..\lib\buckets.ps1"
|
8 | 8 | . "$PSScriptRoot\..\lib\commands.ps1"
|
| 9 | +. "$PSScriptRoot\..\lib\help.ps1" |
| 10 | + |
9 | 11 | # for aliases where there's a local function, re-alias so the function takes precedence
|
10 | 12 | $aliases = Get-Alias | Where-Object { $_.Options -notmatch 'ReadOnly|AllScope' } | ForEach-Object { $_.Name }
|
11 | 13 | Get-ChildItem Function: | Where-Object -Property Name -In -Value $aliases | ForEach-Object {
|
12 | 14 | Set-Alias -Name $_.Name -Value Local:$($_.Name) -Scope Script
|
13 | 15 | }
|
14 | 16 |
|
15 |
| -$commands = commands |
16 |
| -if ('--version' -contains $cmd -or (!$cmd -and '-v' -contains $args)) { |
17 |
| - Write-Host "Current Scoop version:" |
18 |
| - Invoke-Expression "git -C '$(versiondir 'scoop' 'current')' --no-pager log --oneline HEAD -n 1" |
19 |
| - Write-Host "" |
| 17 | +switch ($SubCommand) { |
| 18 | + ({ $SubCommand -in @($null, '--help', '/?') }) { |
| 19 | + if (!$SubCommand -and $Args -eq '-v') { |
| 20 | + $SubCommand = '--version' |
| 21 | + } else { |
| 22 | + exec 'help' |
| 23 | + } |
| 24 | + } |
| 25 | + ({ $SubCommand -eq '--version' }) { |
| 26 | + Write-Host 'Current Scoop version:' |
| 27 | + if ((Test-CommandAvailable git) -and (Test-Path "$PSScriptRoot\..\.git") -and (get_config SCOOP_BRANCH 'master') -ne 'master') { |
| 28 | + Invoke-Expression "git -C '$PSScriptRoot\..' --no-pager log --oneline HEAD -n 1" |
| 29 | + } else { |
| 30 | + $version = Select-String -Pattern '^## \[(v[\d.]+)\].*?([\d-]+)$' -Path "$PSScriptRoot\..\CHANGELOG.md" |
| 31 | + Write-Host $version.Matches.Groups[1].Value -ForegroundColor Cyan -NoNewline |
| 32 | + Write-Host " - Released at $($version.Matches.Groups[2].Value)" |
| 33 | + } |
| 34 | + Write-Host '' |
20 | 35 |
|
21 |
| - Get-LocalBucket | ForEach-Object { |
22 |
| - $bucketLoc = Find-BucketDirectory $_ -Root |
23 |
| - if(Test-Path (Join-Path $bucketLoc '.git')) { |
24 |
| - Write-Host "'$_' bucket:" |
25 |
| - Invoke-Expression "git -C '$bucketLoc' --no-pager log --oneline HEAD -n 1" |
26 |
| - Write-Host "" |
| 36 | + Get-LocalBucket | ForEach-Object { |
| 37 | + $bucketLoc = Find-BucketDirectory $_ -Root |
| 38 | + if ((Test-Path (Join-Path $bucketLoc '.git')) -and (Test-CommandAvailable git)) { |
| 39 | + Write-Host "'$_' bucket:" |
| 40 | + Invoke-Expression "git -C '$bucketLoc' --no-pager log --oneline HEAD -n 1" |
| 41 | + Write-Host '' |
| 42 | + } |
27 | 43 | }
|
28 | 44 | }
|
| 45 | + ({ $SubCommand -in (commands) }) { |
| 46 | + if ($Args -in @('-h', '--help', '/?')) { |
| 47 | + exec 'help' @($SubCommand) |
| 48 | + } else { |
| 49 | + exec $SubCommand $Args |
| 50 | + } |
| 51 | + } |
| 52 | + default { |
| 53 | + "scoop: '$SubCommand' isn't a scoop command. See 'scoop help'." |
| 54 | + exit 1 |
| 55 | + } |
29 | 56 | }
|
30 |
| -elseif (@($null, '--help', '/?') -contains $cmd -or $args[0] -contains '-h') { exec 'help' $args } |
31 |
| -elseif ($commands -contains $cmd) { exec $cmd $args } |
32 |
| -else { "scoop: '$cmd' isn't a scoop command. See 'scoop help'."; exit 1 } |
|
0 commit comments