Skip to content

Commit 8218b61

Browse files
committed
(#3700) Alphabetize all the things
This commit attempts to apply some clear organisation to the ChocolateyTabExpansion.ps1 file by using alphabetical orderding, both in terms of the commands that are listed out, as well as the options that are passed into commands. This will hopefully make this file easier to update, and to see what options are applied where.
1 parent 030ab42 commit 8218b61

File tree

2 files changed

+233
-227
lines changed

2 files changed

+233
-227
lines changed

src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen
3535
Where-Object { $_ -like "$filter*" }
3636
}
3737

38-
$script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','cache','--version','rule')
38+
$script:chocoCommands = @('-?','apikey','cache','config','export','feature','help','info','install','list','new','outdated','pack','pin','push','rule','search','source','template','uninstall','upgrade','-h','--help','--version')
3939

4040
# ensure these all have a space to start, or they will cause issues
41-
$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks --ignore-http-cache"
41+
$allCommands = " --accept-license --cache-location='' --confirm --debug --execution-timeout='' --force --help -? --ignore-http-cache --limit-output --log-file='' --no-color --no-progress --noop --online --proxy='' --proxy-bypass-list='' --proxy-bypass-on-local --proxy-password='' --proxy-user='' --skip-compatibility-checks --trace --verbose"
4242

4343
$commandOptions = @{
44-
list = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --prerelease --include-programs --source='' --page='' --page-size=''"
45-
search = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --approved-only --not-broken --source='' --user='' --password='' --prerelease --include-programs --page='' --page-size='' --order-by-popularity --download-cache-only --disable-package-repository-optimizations --include-configured-sources"
46-
info = "--source='' --local-only --version='' --prerelease --user='' --password='' --cert='' --certpassword='' --disable-package-repository-optimizations --include-configured-sources"
47-
install = "-y -whatif --pre --version='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --force-dependencies --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --stop-on-first-package-failure --disable-package-repository-optimizations --pin --include-configured-sources"
48-
pin = "--name='' --version=''"
49-
outdated = "--source='' --user='' --password='' --ignore-pinned --ignore-unfound --pre --prerelease --disable-package-repository-optimizations --include-configured-sources"
50-
upgrade = "-y -whatif --pre --version='' --except='' --params='' --install-arguments='' --override-arguments --ignore-dependencies --source='' --source='windowsfeatures' --user='' --password='' --prerelease --forcex86 --not-silent --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --allow-downgrade --require-checksums --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --fail-on-unfound --fail-on-not-installed --ignore-checksums --allow-empty-checksums --allow-empty-checksums-secure --download-checksum='' --download-checksum-type='' --download-checksum-x64='' --download-checksum-type-x64='' --exclude-prerelease --stop-on-first-package-failure --use-remembered-options --ignore-remembered-options --skip-when-not-installed --install-if-not-installed --disable-package-repository-optimizations --pin --ignore-pinned --include-configured-sources"
51-
uninstall = "-y -whatif --force-dependencies --remove-dependencies --all-versions --source='windowsfeatures' --version='' --uninstall-arguments='' --override-arguments --not-silent --params='' --package-parameters='' --exit-when-reboot-detected --ignore-detected-reboot --use-package-exit-codes --ignore-package-exit-codes --skip-automation-scripts --use-autouninstaller --skip-autouninstaller --fail-on-autouninstaller --ignore-autouninstaller-failure --stop-on-first-package-failure"
52-
new = "--template-name='' --output-directory='' --automaticpackage --version='' --maintainer='' packageversion='' maintainername='' maintainerrepo='' installertype='' url='' url64='' silentargs='' --use-built-in-template"
53-
pack = "--version='' --output-directory=''"
54-
push = "--source='' --api-key='' --timeout=''"
55-
source = "--name='' --source='' --user='' --password='' --priority='' --bypass-proxy --allow-self-service"
44+
apikey = "--api-key='' --remove --source=''"
45+
cache = "--expired"
5646
config = "--name='' --value=''"
57-
feature = "--name=''"
58-
apikey = "--source='' --api-key='' --remove"
5947
export = "--include-version-numbers --output-file-path=''"
60-
template = "--name=''"
61-
cache = "--expired"
48+
feature = "--name=''"
49+
info = "--cert='' --certpassword='' --disable-package-repository-optimizations --include-configured-sources --local-only --password='' --prerelease --source='' --user='' --version=''"
50+
install = "--allow-downgrade --allow-empty-checksums --allow-empty-checksums-secure --disable-package-repository-optimizations --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --download-checksum-type-x64='' --exit-when-reboot-detected --force-dependencies --forcex86 --ignore-checksums --ignore-dependencies --ignore-detected-reboot --ignore-package-exit-codes --include-configured-sources --install-arguments='' --not-silent --override-arguments --package-parameters='' --params='' --password='' --pin --pre --prerelease --require-checksums --skip-automation-scripts --source='' --source='windowsfeatures' --stop-on-first-package-failure --use-package-exit-codes --user='' --version='' -whatif -y"
51+
list = "--by-id-only --detailed --exact --id-only --id-starts-with --include-programs --page='' --page-size='' --pre --prerelease --source=''"
52+
new = "--automaticpackage installertype='' --maintainer='' maintainername='' maintainerrepo='' --output-directory='' packageversion='' silentargs='' --template-name='' url='' url64='' --use-built-in-template --version=''"
53+
outdated = "--disable-package-repository-optimizations --ignore-pinned --ignore-unfound --include-configured-sources --password='' --pre --prerelease --source='' --user=''"
54+
pack = "--output-directory='' --version=''"
55+
pin = "--name='' --version=''"
56+
push = "--api-key='' --source='' --timeout=''"
6257
rule = "--name=''"
58+
search = "--approved-only --by-id-only --detailed --disable-package-repository-optimizations --download-cache-only --exact --id-only --id-starts-with --include-configured-sources --include-programs --not-broken --order-by-popularity --page='' --page-size='' --password='' --pre --prerelease --source='' --user=''"
59+
source = " --allow-self-service --bypass-proxy --name='' --password='' --priority='' --source='' --user=''"
60+
template = "--name=''"
61+
uninstall = "--all-versions --exit-when-reboot-detected --fail-on-autouninstaller --force-dependencies --ignore-autouninstaller-failure --ignore-detected-reboot --ignore-package-exit-codes --not-silent --override-arguments --params='' --package-parameters='' --remove-dependencies --skip-automation-scripts --skip-autouninstaller --source='windowsfeatures' --stop-on-first-package-failure --uninstall-arguments='' --use-autouninstaller --use-package-exit-codes --version='' -whatif -y"
62+
upgrade = "--allow-downgrade --allow-empty-checksums --allow-empty-checksums-secure --disable-package-repository-optimizations --download-checksum='' --download-checksum-x64='' --download-checksum-type='' --download-checksum-type-x64='' --except='' --exclude-prerelease --exit-when-reboot-detected --fail-on-not-installed --fail-on-unfound --forcex86 --ignore-checksums --ignore-dependencies --ignore-detected-reboot --ignore-package-exit-codes --ignore-pinned --ignore-remembered-options --include-configured-sources --install-arguments='' --install-if-not-installed --not-silent --override-arguments --package-parameters='' --params='' --password='' --pin --pre --prerelease --require-checksums --skip-automation-scripts --skip-when-not-installed --source='' --source='windowsfeatures' --stop-on-first-package-failure --use-package-exit-codes --use-remembered-options --user='' --version='' -whatif -y"
6363
}
6464

6565
$commandOptions['find'] = $commandOptions['search']
@@ -74,16 +74,16 @@ if (Test-Path $licenseFile) {
7474
'optimize'
7575
)
7676

77-
$commandOptions.download = "--internalize --internalize-all-urls --ignore-dependencies --installed-packages --ignore-unfound-packages --resources-location='' --download-location='' --outputdirectory='' --source='' --version='' --prerelease --user='' --password='' --cert='' --certpassword='' --append-use-original-location --recompile --disable-package-repository-optimizations"
78-
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
79-
$commandOptions.optimize = "--deflate-nupkg-only --id=''"
77+
$commandOptions.download = "--append-use-original-location --cert='' --certpassword='' --disable-package-repository-optimizations --download-location='' --ignore-dependencies --ignore-unfound-packages --installed-packages --internalize --internalize-all-urls --outputdirectory='' --password='' --prerelease --recompile --resources-location='' --source='' --user='' --version=''"
78+
$commandOptions.sync = "--id='' --output-directory='' --package-id=''"
79+
$commandOptions.optimize = "--id='' --deflate-nupkg-only"
8080

8181
# Add pro switches to commands that have additional switches on Pro
82-
$proInstallUpgradeOptions = " --install-directory='' --package-parameters-sensitive='' --max-download-rate='' --install-arguments-sensitive='' --skip-download-cache --use-download-cache --skip-virus-check --virus-check --virus-positives-minimum='' --deflate-package-size --no-deflate-package-size --deflate-nupkg-only"
82+
$proInstallUpgradeOptions = " --deflate-nupkg-only--deflate-package-size --install-arguments-sensitive='' --install-directory='' --max-download-rate='' --package-parameters-sensitive='' --no-deflate-package-size --skip-download-cache --skip-virus-check --use-download-cache --virus-check --virus-positives-minimum=''"
8383

8484
$commandOptions.install += $proInstallUpgradeOptions
8585
$commandOptions.upgrade += $proInstallUpgradeOptions + " --exclude-chocolatey-packages-during-upgrade-all --include-chocolatey-packages-during-upgrade-all"
86-
$commandOptions.new += " --build-package --use-original-location --keep-remote --url='' --url64='' --checksum='' --checksum64='' --checksumtype='' --pause-on-error"
86+
$commandOptions.new += " --build-package --checksum='' --checksum64='' --checksumtype='' --keep-remote --pause-on-error --url='' --url64='' --use-original-location"
8787
$commandOptions.pin += " --note=''"
8888

8989
# Add Business-only commands and options if the license is a Business or Trial license
@@ -101,18 +101,18 @@ if (Test-Path $licenseFile) {
101101

102102
$commandOptions.list += " --audit"
103103
$commandOptions.uninstall += " --from-programs-and-features"
104-
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --remove-architecture-from-name --include-architecture-in-name"
104+
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --include-architecture-in-name --remove-architecture-from-name"
105105

106106
# Add --use-self-service to commands that support it
107-
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
107+
$selfServiceCommands = 'download', 'find', 'info', 'install', 'list', 'optimize', 'outdated', 'pin', 'push', 'search', 'sync', 'uninstall', 'upgrade'
108108
foreach ($command in $selfServiceCommands) {
109109
$commandOptions.$command += ' --use-self-service'
110110
}
111111
}
112112
}
113113

114114
foreach ($key in @($commandOptions.Keys)) {
115-
$commandOptions.$key += $allcommands
115+
$commandOptions.$key += $allCommands
116116
}
117117

118118
# Consistent ordering for commands so the added pro commands aren't weirdly out of order
@@ -167,23 +167,28 @@ function Get-AliasPattern($exe) {
167167
function ChocolateyTabExpansion($lastBlock) {
168168
switch -regex ($lastBlock -replace "^$(Get-AliasPattern choco) ", "") {
169169

170-
# Handles uninstall package names
171-
"^uninstall\s+(?<package>[^\.][^-\s]*)$" {
172-
chocoLocalPackages $matches['package']
170+
# Handles cache first tab
171+
"^(cache)\s+(?<subcommand>[^-\s]*)$" {
172+
@('list', 'remove', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
173+
}
174+
175+
# Handles config first tab
176+
"^(config)\s+(?<subcommand>[^-\s]*)$" {
177+
@('list', 'get', 'set', 'unset', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
178+
}
179+
180+
# Handles feature first tab
181+
"^(feature)\s+(?<subcommand>[^-\s]*)$" {
182+
@('list', 'get', 'disable', 'enable', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
173183
}
174184

175185
# Handles install package names
176186
"^(install)\s+(?<package>[^\.][^-\s]+)$" {
177187
chocoRemotePackages $matches['package']
178188
}
179189

180-
# Handles upgrade / uninstall package names
181-
"^upgrade\s+(?<package>[^\.][^-\s]*)$" {
182-
chocoLocalPackagesUpgrade $matches['package']
183-
}
184-
185-
# Handles list/search first tab
186-
"^(list|search|find)\s+(?<subcommand>[^-\s]*)$" {
190+
# Handles list first tab
191+
"^(list)\s+(?<subcommand>[^-\s]*)$" {
187192
@('<filter>', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
188193
}
189194

@@ -197,38 +202,39 @@ function ChocolateyTabExpansion($lastBlock) {
197202
@('<PathtoNuspec>', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
198203
}
199204

205+
# Handles pin first tab
206+
"^(pin)\s+(?<subcommand>[^-\s]*)$" {
207+
@('list', 'add', 'remove', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
208+
}
209+
200210
# Handles push first tab
201211
"^(push)\s+(?<subcommand>[^-\s]*)$" {
202212
@('<PathtoNupkg>', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
203213
}
204214

215+
# Handles search first tab
216+
"^(search|find)\s+(?<subcommand>[^-\s]*)$" {
217+
@('<filter>', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
218+
}
219+
205220
# Handles source first tab
206221
"^(source)\s+(?<subcommand>[^-\s]*)$" {
207222
@('list', 'add', 'remove', 'disable', 'enable', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
208223
}
209224

210-
# Handles pin first tab
211-
"^(pin)\s+(?<subcommand>[^-\s]*)$" {
212-
@('list', 'add', 'remove', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
213-
}
214-
215-
# Handles feature first tab
216-
"^(feature)\s+(?<subcommand>[^-\s]*)$" {
217-
@('list', 'get', 'disable', 'enable', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
218-
}
219-
# Handles config first tab
220-
"^(config)\s+(?<subcommand>[^-\s]*)$" {
221-
@('list', 'get', 'set', 'unset', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
222-
}
223-
224225
# Handles template first tab
225226
"^(template)\s+(?<subcommand>[^-\s]*)$" {
226227
@('list', 'info', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
227228
}
228229

229-
# Handles cache first tab
230-
"^(cache)\s+(?<subcommand>[^-\s]*)$" {
231-
@('list', 'remove', '-?') | Where-Object { $_ -like "$($matches['subcommand'])*" }
230+
# Handles uninstall package names
231+
"^uninstall\s+(?<package>[^\.][^-\s]*)$" {
232+
chocoLocalPackages $matches['package']
233+
}
234+
235+
# Handles upgrade / uninstall package names
236+
"^upgrade\s+(?<package>[^\.][^-\s]*)$" {
237+
chocoLocalPackagesUpgrade $matches['package']
232238
}
233239

234240
# Handles more options after others
@@ -265,21 +271,21 @@ if ($PowerTab_RegisterTabExpansion) {
265271
}
266272

267273
# PowerShell up to v5.x: use a custom TabExpansion function.
268-
if ($PSVersionTable.PSVersion.Major -lt 5) {
274+
if ($PSVersionTable.PSVersion.Major -lt 5) {
269275
if (Test-Path Function:\TabExpansion) {
270276
Rename-Item Function:\TabExpansion TabExpansionBackup
271277
}
272278

273279
function TabExpansion($line, $lastWord) {
274280
$lastBlock = [System.Text.RegularExpressions.Regex]::Split($line, '[|;]')[-1].TrimStart()
275-
281+
276282

277283
switch -regex ($lastBlock) {
278284
# Execute Chocolatey tab completion for all choco-related commands
279285
"^$(Get-AliasPattern choco) (.*)" {
280286
ChocolateyTabExpansion $lastBlock
281287
}
282-
288+
283289
# Fall back on existing tab expansion
284290
default {
285291
if (Test-Path Function:\TabExpansionBackup) {
@@ -293,10 +299,10 @@ else { # PowerShell v5+: use the Register-ArgumentCompleter cmdlet (PowerShell n
293299
function script:Get-AliasNames($exe) {
294300
@($exe) + @(Get-Alias | Where-Object { $_.Definition -eq $exe } | Select-Object -Exp Name)
295301
}
296-
302+
297303
Register-ArgumentCompleter -Native -CommandName (Get-AliasNames choco) -ScriptBlock {
298304
param($wordToComplete, $commandAst, $cursorColumn)
299-
305+
300306
# NOTE:
301307
# * The stringified form of $commandAst is the command's own command line (irrespective of
302308
# whether other statements are on the same line or whether it is part of a pipeline).
@@ -306,7 +312,7 @@ else { # PowerShell v5+: use the Register-ArgumentCompleter cmdlet (PowerShell n
306312
$ownCommandLine = [string] $commandAst
307313
$ownCommandLine = $ownCommandLine.Substring(0, [Math]::Min($ownCommandLine.Length, $cursorColumn))
308314
$ownCommandLine += ' ' * ($cursorColumn - $ownCommandLine.Length)
309-
315+
310316
ChocolateyTabExpansion $ownCommandLine
311317
}
312318
}

0 commit comments

Comments
 (0)