Skip to content

Commit

Permalink
(chocolatey#3218) Update Tab Expansion to use Test-Path
Browse files Browse the repository at this point in the history
The method we were using to clear the error variable wasn't clearing the
variable. Instead of trying this way, it's better to use Test-Path to
verify if a file exists.
  • Loading branch information
corbob committed Jun 20, 2023
1 parent 8b970f3 commit 5640805
Showing 1 changed file with 34 additions and 43 deletions.
77 changes: 34 additions & 43 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,61 +62,52 @@ $commandOptions = @{

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

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

if ($licenseFile) {
# Add pro-only commands
$script:chocoCommands = @(
$script:chocoCommands
'download'
'optimize'
)
if (Test-Path $licenseFile) {
# Add pro-only commands
$script:chocoCommands = @(
$script:chocoCommands
'download'
'optimize'
)

$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"
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
$commandOptions.optimize = "--deflate-nupkg-only --id=''"
$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"
$commandOptions.sync = "--output-directory='' --id='' --package-id=''"
$commandOptions.optimize = "--deflate-nupkg-only --id=''"

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

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

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

if ('Business', 'BusinessTrial' -contains $licenseType) {
if ('Business', 'BusinessTrial' -contains $licenseType) {

# Add business-only commands
$script:chocoCommands = @(
$script:chocoCommands
'support'
'sync'
)
# Add business-only commands
$script:chocoCommands = @(
$script:chocoCommands
'support'
'sync'
)

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

# Add --use-self-service to commands that support it
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
foreach ($command in $selfServiceCommands) {
$commandOptions.$command += ' --use-self-service'
}
# Add --use-self-service to commands that support it
$selfServiceCommands = 'list', 'find', 'search', 'info', 'install', 'upgrade', 'uninstall', 'pin', 'outdated', 'push', 'download', 'sync', 'optimize'
foreach ($command in $selfServiceCommands) {
$commandOptions.$command += ' --use-self-service'
}
}
}
catch {
# Remove the error that last occurred from $error so it doesn't cause any
# issues for users, as we're deliberately ignoring it.
if ($error.Count -gt 0) {
$error.RemoveAt(0)
}
}

foreach ($key in @($commandOptions.Keys)) {
$commandOptions.$key += $allcommands
Expand Down

0 comments on commit 5640805

Please sign in to comment.