-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
596 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<# | ||
.SYNOPSIS | ||
Converts an absolute path to a relative path. | ||
.DESCRIPTION | ||
The ConvertTo-RelativePath command takes an absolute path and converts it | ||
to a relative path based on the current location. If the absolute path | ||
starts with the current location, the function removes the current location | ||
from the beginning of the path and inserts a '.' to indicate the relative path. | ||
.PARAMETER AbsolutePath | ||
Specifies the absolute path that needs to be converted to a relative path. | ||
.PARAMETER CurrentLocation | ||
Specifies the current location used as a reference for converting the absolute | ||
path to a relative path. If not specified, the function uses the current | ||
location obtained from Get-Location. | ||
.EXAMPLE | ||
$convertToRelativePathParameters = @{ | ||
AbsolutePath = '/source/Viscalyx.Common/source/Public/ConvertTo-RelativePath.ps1' | ||
CurrentLocation = "/source/Viscalyx.Common" | ||
} | ||
ConvertTo-RelativePath @convertToRelativePathParameters | ||
Returns "./source/Public/ConvertTo-RelativePath.ps1", which is the | ||
relative path of the given absolute path based on the current location. | ||
.INPUTS | ||
[System.String] | ||
.OUTPUTS | ||
[System.String] | ||
#> | ||
function ConvertTo-RelativePath | ||
Check warning Code scanning / PSScriptAnalyzer Unable to determine parameter set used by example 1 for the function ConvertTo-RelativePath Warning
Unable to determine parameter set used by example 1 for the function ConvertTo-RelativePath
|
||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | ||
[System.String] | ||
$AbsolutePath, | ||
|
||
[Parameter(Position = 1)] | ||
[System.String] | ||
$CurrentLocation | ||
) | ||
|
||
begin | ||
{ | ||
if (-not $PSBoundParameters.ContainsKey('CurrentLocation')) | ||
{ | ||
$CurrentLocation = (Get-Location).Path | ||
} | ||
} | ||
|
||
process | ||
{ | ||
$relativePath = $AbsolutePath | ||
|
||
if ($relativePath.StartsWith($CurrentLocation)) | ||
{ | ||
$relativePath = $relativePath.Substring($CurrentLocation.Length).Insert(0, '.') | ||
} | ||
|
||
return $relativePath | ||
} | ||
} |
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,48 @@ | ||
function Get-ModuleVersion | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | ||
[System.Object] | ||
$Module | ||
) | ||
|
||
process | ||
{ | ||
$moduleInfo = $null | ||
$moduleVersion = $null | ||
|
||
if ($Module -is [System.String]) | ||
{ | ||
$moduleInfo = Get-Module -Name $Module -ErrorAction 'Stop' | ||
|
||
if (-not $moduleInfo) | ||
{ | ||
Write-Error -Message "Cannot find the module '$Module'. Make sure it is loaded into the session." | ||
} | ||
} | ||
elseif ($Module -is [System.Management.Automation.PSModuleInfo]) | ||
{ | ||
$moduleInfo = $Module | ||
} | ||
else | ||
{ | ||
Write-Error -Message "Invalid parameter type. The parameter 'Module' must be either a string or a PSModuleInfo object." | ||
} | ||
|
||
if ($moduleInfo) | ||
{ | ||
$moduleVersion = $moduleInfo.Version.ToString() | ||
|
||
$previewReleaseTag = $moduleInfo.PrivateData.PSData.Prerelease | ||
|
||
if ($previewReleaseTag) | ||
{ | ||
$moduleVersion += '-{0}' -f $previewReleaseTag | ||
} | ||
} | ||
|
||
return $moduleVersion | ||
} | ||
} |
Oops, something went wrong.