You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I've been trying out a manifest and template file to spin up a new PowerShell function works great and I can see the value. However, from what I can tell the only option is to put each function into its own file. Is there some way to append to a file on subsequent runs of a Plaster manifest?
Ideally I could invoke a Plaster manifest to scaffold out a new module and then run a manifest to sketch out the functions in a psm1 file.
There is currently a modifyFile directive that is oriented around regex modifications. That could be used to append to a file I think. We could add an appendFile directive but one of the principles we've been trying to maintain is that you run the template on an existing directory and that would work reasonably well. Hence the modifyFile directive IIRC wouldn't modify a file if it detects the modifications are already in place. That said, we could allow for the same condition checking on an appendFile directive.
I'm thinking more along the lines of when I use a template like this:
<?xml version="1.0" encoding="utf-8"?>
<plasterManifest
schemaVersion="1.1"
templateType="Item" xmlns="http://www.microsoft.com/schemas/PowerShell/Plaster/v1">
<metadata>
<name>myFunction</name>
<id>1e3644a0-53bf-427e-8c5c-94b804343d85</id>
<version>0.9.0</version>
<title>myFunction</title>
<description>Template for a PowerShell advanced function</description>
<author>Jeff Hicks</author>
<tags>function</tags>
</metadata>
<parameters>
<parameter name='Name' type='text' prompt='Enter the name of your function.'/>
<parameter name="ShouldProcess" type="choice" prompt="Do you need to support -WhatIf>" default='1'>
<choice label="&Yes" help="Adds SupportsShouldProcess" value="Yes" />
<choice label="&No" help="Does not add SupportsShouldProcess" value="No" />
</parameter>
<parameter name="Help" type="choice" prompt="Do you need comment based help?>" default='1'>
<choice label="&Yes" help="Add comment based help outline" value="Yes" />
<choice label="&No" help="Does not add comment based help" value="No" />
</parameter>
<parameter name="ComputerName" type="choice" prompt="Add a parameter for Computername?>" default='0'>
<choice label="&Yes" help="Adds a default parameter for computername" value="Yes" />
<choice label="&No" help="Does not include computername parameter" value="No" />
</parameter>
</parameters>
<content>
<message> Scaffolding your PowerShell function $PLASTER_PARAM_Name... </message>
<templateFile source='template.ps1' destination='${PLASTER_PARAM_Name}.ps1'/>
<message>Your function, '$PLASTER_PARAM_Name', has been saved to '$PLASTER_DestinationPath\$PLASTER_PARAM_Name.ps1'</message>
</content>
</plasterManifest>
Right now if I run Invoke-Plaster 3 times to create a Get-Foo, Set-Foo and Invoke-Foo, I end up with 3 separate files where ideally I'd like to put them all in a single ps1 or psm1 file. I can probably work around this with some tooling that would create the files then merge the contents into a single file.
Activity
rkeithhill commentedon Jan 31, 2018
There is currently a modifyFile directive that is oriented around regex modifications. That could be used to append to a file I think. We could add an appendFile directive but one of the principles we've been trying to maintain is that you run the template on an existing directory and that would work reasonably well. Hence the modifyFile directive IIRC wouldn't modify a file if it detects the modifications are already in place. That said, we could allow for the same condition checking on an appendFile directive.
jdhitsolutions commentedon Feb 1, 2018
I'm thinking more along the lines of when I use a template like this:
Right now if I run Invoke-Plaster 3 times to create a Get-Foo, Set-Foo and Invoke-Foo, I end up with 3 separate files where ideally I'd like to put them all in a single ps1 or psm1 file. I can probably work around this with some tooling that would create the files then merge the contents into a single file.