Scenario: I want to create a path for a new module. If the user answers 'yes' to the question of whether or not to create a Git top level folder, they receive an additional prompt for a 'GitRepoName' and that name is used to create an additional top level folder that the module folder is a sub-folder of.
Parameters: Name, Git, GitRepoName
If Git = Yes, then the folder structure should look like this:
\GitRepoName\Name
If Git = No, then it should like like this:
\Name
The problem is that a condition that evaluates to false still validates the path specified in that line of the manifest.
Sample PlasterTemplate.xml file
<?xml version="1.0" encoding="utf-8"?>
<plasterManifest schemaVersion="1.1" templateType="Project" xmlns="http://www.microsoft.com/schemas/PowerShell/Plaster/v1">
<metadata>
<name>ScriptModuleTemplate</name>
<id>e4b0f5db-b8cf-45ab-b0bd-76abfeb72e33</id>
<version>1.0.0</version>
<title>Script Module Template</title>
<description></description>
<author>Mike F. Robbins</author>
<tags></tags>
</metadata>
<parameters>
<parameter name="Name" type="text" prompt="Name of the module"/>
<parameter name="Git" type="choice" default="0" prompt="Create Git top level folder?">
<choice label="&Yes" value="Yes" help="Create a top level folder for Git with module folder nested in it."/>
<choice label="&No" value="No" help="No Git top level folder. Module folder will be the root."/>
</parameter>
<parameter condition="$PLASTER_PARAM_Git -eq 'Yes'" name="GitRepoName" type="text" prompt="Git repo name for this module? Press enter if not using Git." default="${PLASTER_PARAM_Name}"/>
</parameters>
<content>
<message>Creating folder structure</message>
<file condition="$PLASTER_PARAM_Git -eq 'Yes'" source="" destination="${PLASTER_PARAM_GitRepoName}\${PLASTER_PARAM_Name}"/>
<file condition="$PLASTER_PARAM_Git -eq 'No'" source="" destination="${PLASTER_PARAM_Name}"/>
</content>
</plasterManifest>
Sample code to generate the folder structure:
#Create a new PowerShell Script module
$plasterParams = @{
TemplatePath = 'C:\tmp\Plaster'
DestinationPath = 'C:\tmp'
Name = 'MyModule'
Git = 'No'
GitRepoName = 'MyRepo'
}
If (-not(Test-Path -Path $plasterParams.DestinationPath -PathType Container)) {
New-Item -Path $plasterParams.DestinationPath -ItemType Directory | Out-Null
}
Invoke-Plaster @plasterParams
The following error is generated when 'Git' is set to 'No':
The path '\MyModule' 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.3\InvokePlaster.ps1:1075 char:17
+ ... throw ($LocalizedData.ErrorPathMustBeRelativePath_F2 -f $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (The path '\MyMo... relative path.:String) [], RuntimeException
+ FullyQualifiedErrorId : The path '\MyModule' specified in the file directive in the template manifest cannot be an absolute path.
Change the path to a relative path.
This is due to the path in the following line being validated even when the condition evaluates to false:
<file condition="$PLASTER_PARAM_Git -eq 'Yes'" source="" destination="${PLASTER_PARAM_GitRepoName}\${PLASTER_PARAM_Name}"/>
The problem can be worked around by prompting the user for a 'GitRepoName' even when it's not used, but this shouldn't be required.
Scenario: I want to create a path for a new module. If the user answers 'yes' to the question of whether or not to create a Git top level folder, they receive an additional prompt for a 'GitRepoName' and that name is used to create an additional top level folder that the module folder is a sub-folder of.
Parameters: Name, Git, GitRepoName
If Git = Yes, then the folder structure should look like this:
\GitRepoName\Name
If Git = No, then it should like like this:
\Name
The problem is that a condition that evaluates to false still validates the path specified in that line of the manifest.
Sample PlasterTemplate.xml file
Sample code to generate the folder structure:
The following error is generated when 'Git' is set to 'No':
This is due to the path in the following line being validated even when the condition evaluates to false:
The problem can be worked around by prompting the user for a 'GitRepoName' even when it's not used, but this shouldn't be required.