Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command Invoke-PesterJob #8

Merged
merged 17 commits into from
Sep 2, 2024
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
65 changes: 65 additions & 0 deletions source/Public/ConvertTo-RelativePath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<#
.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
ConvertTo-RelativePath -AbsolutePath '/source/Viscalyx.Common/source/Public/ConvertTo-RelativePath.ps1' -CurrentLocation "/source/Viscalyx.Common"

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
Fixed Show fixed Hide fixed
{
[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'))

Check warning on line 48 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L48

Added line #L48 was not covered by tests
{
$CurrentLocation = (Get-Location).Path

Check warning on line 50 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L50

Added line #L50 was not covered by tests
}
}

process
{
$relativePath = $AbsolutePath

Check warning on line 56 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L56

Added line #L56 was not covered by tests

if ($relativePath.StartsWith($CurrentLocation))

Check warning on line 58 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L58

Added line #L58 was not covered by tests
{
$relativePath = $relativePath.Substring($CurrentLocation.Length).Insert(0, '.')

Check warning on line 60 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L60

Added line #L60 was not covered by tests
}

return $relativePath

Check warning on line 63 in source/Public/ConvertTo-RelativePath.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/ConvertTo-RelativePath.ps1#L63

Added line #L63 was not covered by tests
}
}
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

Check warning on line 14 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L13-L14

Added lines #L13 - L14 were not covered by tests

if ($Module -is [System.String])

Check warning on line 16 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L16

Added line #L16 was not covered by tests
{
$moduleInfo = Get-Module -Name $Module -ErrorAction 'Stop'

Check warning on line 18 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L18

Added line #L18 was not covered by tests

if (-not $moduleInfo)

Check warning on line 20 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L20

Added line #L20 was not covered by tests
{
Write-Error -Message "Cannot find the module '$Module'. Make sure it is loaded into the session."

Check warning on line 22 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L22

Added line #L22 was not covered by tests
}
}
elseif ($Module -is [System.Management.Automation.PSModuleInfo])

Check warning on line 25 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L25

Added line #L25 was not covered by tests
{
$moduleInfo = $Module

Check warning on line 27 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L27

Added line #L27 was not covered by tests
}
else
{
Write-Error -Message "Invalid parameter type. The parameter 'Module' must be either a string or a PSModuleInfo object."

Check warning on line 31 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L31

Added line #L31 was not covered by tests
}

if ($moduleInfo)

Check warning on line 34 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L34

Added line #L34 was not covered by tests
{
$moduleVersion = $moduleInfo.Version.ToString()

Check warning on line 36 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L36

Added line #L36 was not covered by tests

$previewReleaseTag = $moduleInfo.PrivateData.PSData.Prerelease

Check warning on line 38 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L38

Added line #L38 was not covered by tests

if ($previewReleaseTag)

Check warning on line 40 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L40

Added line #L40 was not covered by tests
{
$moduleVersion += '-{0}' -f $previewReleaseTag

Check warning on line 42 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L42

Added line #L42 was not covered by tests
}
}

return $moduleVersion

Check warning on line 46 in source/Public/Get-ModuleVersion.ps1

View check run for this annotation

Codecov / codecov/patch

source/Public/Get-ModuleVersion.ps1#L46

Added line #L46 was not covered by tests
}
}
Loading
Loading