@@ -35,31 +35,31 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen
35
35
Where-Object { $_ -like " $filter *" }
36
36
}
37
37
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 ' )
39
39
40
40
# 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 "
42
42
43
43
$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"
56
46
config = " --name='' --value=''"
57
- feature = " --name=''"
58
- apikey = " --source='' --api-key='' --remove"
59
47
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=''"
62
57
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"
63
63
}
64
64
65
65
$commandOptions [' find' ] = $commandOptions [' search' ]
@@ -74,16 +74,16 @@ if (Test-Path $licenseFile) {
74
74
' optimize'
75
75
)
76
76
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"
80
80
81
81
# 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=''"
83
83
84
84
$commandOptions.install += $proInstallUpgradeOptions
85
85
$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 "
87
87
$commandOptions.pin += " --note=''"
88
88
89
89
# Add Business-only commands and options if the license is a Business or Trial license
@@ -101,18 +101,18 @@ if (Test-Path $licenseFile) {
101
101
102
102
$commandOptions.list += " --audit"
103
103
$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"
105
105
106
106
# 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 '
108
108
foreach ($command in $selfServiceCommands ) {
109
109
$commandOptions .$command += ' --use-self-service'
110
110
}
111
111
}
112
112
}
113
113
114
114
foreach ($key in @ ($commandOptions.Keys )) {
115
- $commandOptions .$key += $allcommands
115
+ $commandOptions .$key += $allCommands
116
116
}
117
117
118
118
# Consistent ordering for commands so the added pro commands aren't weirdly out of order
@@ -167,23 +167,28 @@ function Get-AliasPattern($exe) {
167
167
function ChocolateyTabExpansion ($lastBlock ) {
168
168
switch - regex ($lastBlock -replace " ^$ ( Get-AliasPattern choco) " , " " ) {
169
169
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' ]) *" }
173
183
}
174
184
175
185
# Handles install package names
176
186
" ^(install)\s+(?<package>[^\.][^-\s]+)$" {
177
187
chocoRemotePackages $matches [' package' ]
178
188
}
179
189
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]*)$" {
187
192
@ (' <filter>' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
188
193
}
189
194
@@ -197,38 +202,39 @@ function ChocolateyTabExpansion($lastBlock) {
197
202
@ (' <PathtoNuspec>' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
198
203
}
199
204
205
+ # Handles pin first tab
206
+ " ^(pin)\s+(?<subcommand>[^-\s]*)$" {
207
+ @ (' list' , ' add' , ' remove' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
208
+ }
209
+
200
210
# Handles push first tab
201
211
" ^(push)\s+(?<subcommand>[^-\s]*)$" {
202
212
@ (' <PathtoNupkg>' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
203
213
}
204
214
215
+ # Handles search first tab
216
+ " ^(search|find)\s+(?<subcommand>[^-\s]*)$" {
217
+ @ (' <filter>' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
218
+ }
219
+
205
220
# Handles source first tab
206
221
" ^(source)\s+(?<subcommand>[^-\s]*)$" {
207
222
@ (' list' , ' add' , ' remove' , ' disable' , ' enable' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
208
223
}
209
224
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
-
224
225
# Handles template first tab
225
226
" ^(template)\s+(?<subcommand>[^-\s]*)$" {
226
227
@ (' list' , ' info' , ' -?' ) | Where-Object { $_ -like " $ ( $matches [' subcommand' ]) *" }
227
228
}
228
229
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' ]
232
238
}
233
239
234
240
# Handles more options after others
@@ -265,21 +271,21 @@ if ($PowerTab_RegisterTabExpansion) {
265
271
}
266
272
267
273
# PowerShell up to v5.x: use a custom TabExpansion function.
268
- if ($PSVersionTable.PSVersion.Major -lt 5 ) {
274
+ if ($PSVersionTable.PSVersion.Major -lt 5 ) {
269
275
if (Test-Path Function:\TabExpansion) {
270
276
Rename-Item Function:\TabExpansion TabExpansionBackup
271
277
}
272
278
273
279
function TabExpansion ($line , $lastWord ) {
274
280
$lastBlock = [System.Text.RegularExpressions.Regex ]::Split($line , ' [|;]' )[-1 ].TrimStart()
275
-
281
+
276
282
277
283
switch - regex ($lastBlock ) {
278
284
# Execute Chocolatey tab completion for all choco-related commands
279
285
" ^$ ( Get-AliasPattern choco) (.*)" {
280
286
ChocolateyTabExpansion $lastBlock
281
287
}
282
-
288
+
283
289
# Fall back on existing tab expansion
284
290
default {
285
291
if (Test-Path Function:\TabExpansionBackup) {
@@ -293,10 +299,10 @@ else { # PowerShell v5+: use the Register-ArgumentCompleter cmdlet (PowerShell n
293
299
function script :Get-AliasNames ($exe ) {
294
300
@ ($exe ) + @ (Get-Alias | Where-Object { $_.Definition -eq $exe } | Select-Object - Exp Name)
295
301
}
296
-
302
+
297
303
Register-ArgumentCompleter - Native - CommandName (Get-AliasNames choco) - ScriptBlock {
298
304
param ($wordToComplete , $commandAst , $cursorColumn )
299
-
305
+
300
306
# NOTE:
301
307
# * The stringified form of $commandAst is the command's own command line (irrespective of
302
308
# 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
306
312
$ownCommandLine = [string ] $commandAst
307
313
$ownCommandLine = $ownCommandLine.Substring (0 , [Math ]::Min($ownCommandLine.Length , $cursorColumn ))
308
314
$ownCommandLine += ' ' * ($cursorColumn - $ownCommandLine.Length )
309
-
315
+
310
316
ChocolateyTabExpansion $ownCommandLine
311
317
}
312
318
}
0 commit comments