Skip to content

Commit

Permalink
Add command Invoke-PesterJob
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 1, 2024
1 parent e0945c5 commit 3ca16e4
Show file tree
Hide file tree
Showing 5 changed files with 596 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Public commands:
- `Invoke-PesterJob`
- `Get-ModuleVersion`
- `ConvertTo-RelativePath`

## [0.2.0] - 2024-08-25

### Added
Expand All @@ -14,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ConvertTo-DifferenceString`
- `Get-NumericalSequence`
- `Get-PSReadLineHistory`
- `Invoke-PesterJob`
- `New-SamplerGitHubReleaseTag`
- `Out-Difference`
- `Pop-VMLatestSnapShot`
Expand Down
69 changes: 69 additions & 0 deletions source/Public/ConvertTo-RelativePath.ps1
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
}
}
48 changes: 48 additions & 0 deletions source/Public/Get-ModuleVersion.ps1
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
}
}
Loading

0 comments on commit 3ca16e4

Please sign in to comment.