Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Feature request: Append to destination file #308

Closed
jdhitsolutions opened this issue Jan 31, 2018 · 2 comments
Closed

Feature request: Append to destination file #308

jdhitsolutions opened this issue Jan 31, 2018 · 2 comments

Comments

@jdhitsolutions
Copy link
Contributor

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.

@rkeithhill
Copy link
Collaborator

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
Copy link
Contributor Author

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="&amp;Yes" help="Adds SupportsShouldProcess" value="Yes" />
        <choice label="&amp;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="&amp;Yes" help="Add comment based help outline" value="Yes" />
        <choice label="&amp;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="&amp;Yes" help="Adds a default parameter for computername" value="Yes" />
        <choice label="&amp;No" help="Does not include computername parameter" value="No" />
        </parameter>
  </parameters>
  <content>
      <message>&#10;&#10;Scaffolding your PowerShell function $PLASTER_PARAM_Name...&#10;&#10;&#10;</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.

@PowerShellOrg PowerShellOrg locked and limited conversation to collaborators Feb 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants