PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

[Feature Request] -RequiredResource(File) for Save-Module

Open JustinGrote opened this issue 5 years ago • 6 comments

There are many circumstances where you want to install modules to somewhere other than the powershell modules folder, for instance if creating the equivalent of a python "virtual environment" for CI builds, or other circumstances where you want a module but don't want to deploy it to the main path.

Save-Module usually fulfills this use path, and as such it should support the same items for "restore"-like functionality

Alternatively, add -Path or -Destination parameter to Install-Module to specify an alternate location. It should be in a different parameter set then -Scope

JustinGrote avatar May 15 '20 22:05 JustinGrote

This is actually covered in the RFC as the -DestinationPath parameter. I suggest it be altered to -Destination because this would be more familiar to most Powershell users since Move-Item, Copy-Item use -Destination and not -DestinationPath image

SYNTAX
    Move-Item [-Path] <string[]> [[-Destination] <string>] [-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]    
    [<CommonParameters>]

    Move-Item [[-Destination] <string>] -LiteralPath <string[]> [-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
    [-UseTransaction]  [<CommonParameters>]

JustinGrote avatar May 19 '20 18:05 JustinGrote

@JustinGrote thanks for opening this issue, we certainly intend to provide this functionality...one open question Amber and I have been discussing is if it makes more sense to provide this experience through a -Destination parameter on Install or through the Save cmdlet...do you have any insight as to which experience you prefer?

SydneyhSmith avatar May 22 '20 18:05 SydneyhSmith

I would suggest it on Save since most users are familiar with that workflow from 2.x for putting modules in a location other than the default modules directories., and the only difference is that it doesn't drop the XML metadata for the repository into the destination.

It makes sense to do it on both commands, the difference between install and save being that save wouldn't drop the xml "installed" metadata into the folder whereas install would.

In an ideal world, the code flow would be that Install basically calls the save module function to a specific path, and then does the additional xml stuff afterwards. That way there's no redundant methods.

But, if I had to pick one, do it on Save and allow it to accept the same RequiredResource(file) for save module.

Once that's done it'd be trivial to make a "Restore-PSResource" command that would basically automate looking for a requirements.psd1 or something file in the current directory, and output to a predefined path, to give that "dotnet restore" or "nupkg restore" or "pip install -r requirements.txt" behavior users coming from other languages may be expecting.

JustinGrote avatar May 22 '20 19:05 JustinGrote