Skip to content

Feature request: Append to destination file #308

Closed

Description

@jdhitsolutions

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.

Activity

  1. rkeithhill commented on Jan 31, 2018

    @rkeithhill
    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.

  2. jdhitsolutions commented on Feb 1, 2018

    @jdhitsolutions
    ContributorAuthor

    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.

  3. locked and limited conversation to collaborators on Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions