gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
171 stars 42 forks source link

Add-Sample function requires a relative path, but suggests an absolute path when using PrivateFunction #441

Closed ykuijs closed 1 year ago

ykuijs commented 1 year ago

Problem description

When using Add-Sample, the first question that is asked is "What is your source folder". When using PrivateFunction for the Sample parameter, the code suggests the full path of the local folder and adds Source behind it. When continuing, it then throws an exception mentioning it does not support an absolute path:

When you specify PublicFunction, it correctly suggest a relative path to the Source folder:

PS C:\Temp\Dsc\M365DSCTools> Add-Sample -Sample PublicFunction -PublicFunctionName Get-PublicFunction
  ____  _           _
 |  _ \| | __ _ ___| |_ ___ _ __
 | |_) | |/ _` / __| __/ _ \ '__|
 |  __/| | (_| \__ \ ||  __/ |
 |_|   |_|\__,_|___/\__\___|_|
                                            v1.1.4
==================================================
What is your source folder? (source): 
Destination path: C:\Temp\Dsc\M365DSCTools
   Create tests/Unit/Public\
   Create source\Public\Get-PublicFunction.ps1
   Create tests\Unit\Public\Get-PublicFunction.tests.ps1

Verbose logs

Example with PrivateFunction:
PS C:\Temp\Dsc\M365DSCTools> Add-Sample -Sample PrivateFunction -PrivateFunctionName Get-PrivateFunction
  ____  _           _
 |  _ \| | __ _ ___| |_ ___ _ __
 | |_) | |/ _` / __| __/ _ \ '__|
 |  __/| | (_| \__ \ ||  __/ |
 |_|   |_|\__,_|___/\__\___|_|
                                            v1.1.4
==================================================
What is your source folder? (C:\Temp\Dsc\M365DSCTools\Source): 
Destination path: C:\Temp\Dsc\M365DSCTools
The path 'C:\Temp\Dsc\M365DSCTools\Source/Private' specified in the file directive in the template manifest cannot be an absolute path.  Change the path to a relative path.
At C:\Program Files\WindowsPowerShell\Modules\Plaster\1.1.4\InvokePlaster.ps1:1092 char:17
+ ...             throw ($LocalizedData.ErrorPathMustBeRelativePath_F2 -f $ ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (The path 'C:\Te... relative path.:String) [], RuntimeException
    + FullyQualifiedErrorId : The path 'C:\Temp\Dsc\M365DSCTools\Source/Private' specified in the file directive in the template manifest cannot be an absolute path.  Change the path to a  
   relative path.

Example with PublicFunction:
PS C:\Temp\Dsc\M365DSCTools> Add-Sample -Sample PublicFunction -PublicFunctionName Get-PublicFunction
  ____  _           _
 |  _ \| | __ _ ___| |_ ___ _ __
 | |_) | |/ _` / __| __/ _ \ '__|
 |  __/| | (_| \__ \ ||  __/ |
 |_|   |_|\__,_|___/\__\___|_|
                                            v1.1.4
==================================================
What is your source folder? (source): 
Destination path: C:\Temp\Dsc\M365DSCTools
   Create tests/Unit/Public\
   Create source\Public\Get-PublicFunction.ps1
   Create tests\Unit\Public\Get-PublicFunction.tests.ps1

How to reproduce

Run Add-Sample -Sample PrivateFunction -PrivateFunctionName Get-PrivateFunction

Expected behavior

Suggest a relative path when the code expects that.

Current behavior

The code suggests an absolute path

Suggested solution

Change the code to suggest a relative path, just like it does for PublicFunction

Operating system the target node is running

OsName               : Microsoft Windows 11 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22621.1.amd64fre.ni_release.220506-1250
OsLanguage           : en-US
OsMuiLanguages       : {en-US, en-GB, nl-NL}

PowerShell version and build the target node is running

Name                           Value                                                                                                                                                         
----                           -----                                                                                                                                                         
PSVersion                      5.1.22621.1778                                                                                                                                                
PSEdition                      Desktop                                                                                                                                                       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                       
BuildVersion                   10.0.22621.1778                                                                                                                                               
CLRVersion                     4.0.30319.42000                                                                                                                                               
WSManStackVersion              3.0                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                           
SerializationVersion           1.1.0.1

Module version used

Name    Version Path                                                                        
----    ------- ----                                                                        
Sampler 0.116.5 C:\Program Files\WindowsPowerShell\Modules\Sampler\0.116.5\Sampler.psd1
ykuijs commented 1 year ago

Never mind, it uses the last used value.