-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/2.1.0: (52 commits) (maint) If statement formatting change (#3224) Add Assembly Loaded configuration option (maint) Resave without BOM (#3224) Update version check tests (#3174) Store non-normalized package version (maint) Add required whitespace (#3225) Add Pester Tests to ensure environment (#3201 #3225) Re-instate setting of config values (maint) Remove env variable for release version (maint) Fix encoding of file (#3194) Add tab completion for cache command (#2854) Re-save file with UTF-8 with BOM (#3218) Update Tab Expansion to use Test-Path (#3218) Remove try catch block for tab completion (build) Use latest Chocolatey.Cake.Recipe package (#2854) Do Write-Error instead of Write-Warning (#2854) Pester tests to Get-ChocolateyConfigValue (maint) Resave Get-ChocolateyConfigValue as CRLF (#2854) Add helper to read config values (#3214) Add Pester tests to ensure cache cleared ...
- Loading branch information
Showing
118 changed files
with
4,259 additions
and
3,883 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/chocolatey.resources/helpers/functions/Get-ChocolateyConfigValue.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright © 2022 Chocolatey Software, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
function Get-ChocolateyConfigValue { | ||
<# | ||
.SYNOPSIS | ||
Retrieve a value from the Chocolatey Configuration file | ||
.DESCRIPTION | ||
This function will attempt to retrieve the path according to the specified Path Type | ||
to a valid location that can be used by maintainers in certain scenarios. | ||
.NOTES | ||
Available in 2.1.0+ | ||
.INPUTS | ||
None | ||
.OUTPUTS | ||
This function outputs the value of the specified configuration key. | ||
If the key is not found, there is no output. | ||
.PARAMETER configKey | ||
The name of the configuration value that should be looked up. | ||
.PARAMETER IgnoredArguments | ||
Allows splatting with arguments that do not apply. Do not use directly. | ||
.EXAMPLE | ||
> | ||
$value = Get-ChocolateyConfigValue -configKey 'cacheLocation' | ||
#> | ||
param( | ||
[parameter(Mandatory = $true)] | ||
[string] $configKey, | ||
[parameter(ValueFromRemainingArguments = $true)] | ||
[Object[]] $ignoredArguments | ||
) | ||
|
||
try { | ||
$installLocation = Get-ChocolateyPath -pathType 'InstallPath' | ||
$configPath = Join-Path $installLocation "config\chocolatey.config" | ||
[xml]$configContents = Get-Content -Path $configPath | ||
return $configContents.chocolatey.config.add | | ||
Where-Object { $_.key -eq $configKey } | | ||
Select-Object -ExpandProperty value | ||
} | ||
catch { | ||
Write-Error "Unable to read config value '$configKey' with error" -Exception $_ | ||
} | ||
} |
Oops, something went wrong.