Skip to content

Commit 24aa224

Browse files
committed
(chocolatey#3218) Remove try catch block for tab completion
1 parent f96f014 commit 24aa224

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -62,61 +62,52 @@ $commandOptions = @{
6262

6363
$commandOptions['find'] = $commandOptions['search']
6464

65-
try {
66-
$licenseFile = Get-Item -Path "$env:ChocolateyInstall\license\chocolatey.license.xml" -ErrorAction Stop
65+
$licenseFile = Get-Item -Path "$env:ChocolateyInstall\license\chocolatey.license.xml" -ErrorAction Stop
6766

68-
if ($licenseFile) {
69-
# Add pro-only commands
70-
$script:chocoCommands = @(
71-
$script:chocoCommands
72-
'download'
73-
'optimize'
74-
)
67+
if ($licenseFile) {
68+
# Add pro-only commands
69+
$script:chocoCommands = @(
70+
$script:chocoCommands
71+
'download'
72+
'optimize'
73+
)
7574

76-
$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"
77-
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
78-
$commandOptions.optimize = "--deflate-nupkg-only --id=''"
75+
$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"
76+
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
77+
$commandOptions.optimize = "--deflate-nupkg-only --id=''"
7978

80-
# Add pro switches to commands that have additional switches on Pro
81-
$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"
79+
# Add pro switches to commands that have additional switches on Pro
80+
$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"
8281

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

88-
# Add Business-only commands and options if the license is a Business or Trial license
89-
[xml]$xml = Get-Content -Path $licenseFile.FullName -ErrorAction Stop
90-
$licenseType = $xml.license.type
87+
# Add Business-only commands and options if the license is a Business or Trial license
88+
[xml]$xml = Get-Content -Path $licenseFile.FullName -ErrorAction Stop
89+
$licenseType = $xml.license.type
9190

92-
if ('Business', 'BusinessTrial' -contains $licenseType) {
91+
if ('Business', 'BusinessTrial' -contains $licenseType) {
9392

94-
# Add business-only commands
95-
$script:chocoCommands = @(
96-
$script:chocoCommands
97-
'support'
98-
'sync'
99-
)
93+
# Add business-only commands
94+
$script:chocoCommands = @(
95+
$script:chocoCommands
96+
'support'
97+
'sync'
98+
)
10099

101-
$commandOptions.list += " --audit"
102-
$commandOptions.uninstall += " --from-programs-and-features"
103-
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --remove-architecture-from-name --include-architecture-in-name"
100+
$commandOptions.list += " --audit"
101+
$commandOptions.uninstall += " --from-programs-and-features"
102+
$commandOptions.new += " --file='' --file64='' --from-programs-and-features --remove-architecture-from-name --include-architecture-in-name"
104103

105-
# Add --use-self-service to commands that support it
106-
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
107-
foreach ($command in $selfServiceCommands) {
108-
$commandOptions.$command += ' --use-self-service'
109-
}
104+
# Add --use-self-service to commands that support it
105+
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
106+
foreach ($command in $selfServiceCommands) {
107+
$commandOptions.$command += ' --use-self-service'
110108
}
111109
}
112110
}
113-
catch {
114-
# Remove the error that last occurred from $error so it doesn't cause any
115-
# issues for users, as we're deliberately ignoring it.
116-
if ($error.Count -gt 0) {
117-
$error.RemoveAt(0)
118-
}
119-
}
120111

121112
foreach ($key in @($commandOptions.Keys)) {
122113
$commandOptions.$key += $allcommands

0 commit comments

Comments
 (0)