jpsider / RestPS

Simple ReST Framework for Powershell
MIT License
114 stars 30 forks source link

Invoke-DeployRestPS generates an error when only a single version of the RestPS module is installed #21

Closed mikefrobbins closed 6 years ago

mikefrobbins commented 6 years ago

To reproduce this problem, only have RestPS version 7.0.4 installed (have not tested with other versions). When Invoke-DeployRestPS is run, the following error is generated along with lots of the same types of errors.

Copy-Item : Cannot find path 'C:\C\endpoints\Invoke-AvailableRouteSet.ps1' because it does not exist.
At C:\Program Files\WindowsPowerShell\Modules\RestPS\7.0.4\RestPS.psm1:368 char:9
+         Copy-Item -Path "$RoutesFileSource" -Destination $LocalDir\En ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\C\endpoints\...bleRouteSet.ps1:String) [Copy-Item], ItemNotFoundExce
   ption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

This is due to line 38 of Invoke-DeployRestPS.ps1 expecting a collection of items:

$Source = (Split-Path -Path (Get-Module -ListAvailable RestPS).path)[0]

When only a single path is returned, the previous code causes only the first character in the path to be added to the $Source variable. When more than one version of the RestPS module is installed, it returns a collection and the first path is stored in the $Source variable.

Consider using different logic like the following instead of an element in a collection to select a single path.

$Source = (Split-Path -Path (Get-Module -ListAvailable RestPS | Sort-Object -Property Version -Descending | Select-Object -First 1).path)

I'll submit a PR to fix this particular problem.

Also consider adding a parameter to Invoke-DeployRestPS in case the user needs to deploy with a specific version of the RestPS module (if there's any difference).