Skip to content
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

(chocolatey-core.extension) add helper to set install location #16

Open
TheCakeIsNaOH opened this issue Feb 10, 2024 · 1 comment
Open
Labels
core extension enhancement New feature or request

Comments

@TheCakeIsNaOH
Copy link
Member

Sometimes, it may be desirable to set the installation directory manually in an install script. This can be done by setting $env:ChocolateyPackageInstallLocation, however, it would be good to have a helper that abstracts the functionality. It should not set the variable if it is already set, unless force is passed.

This is so the install directory can be set for installers that do not set an explicit install directory in the registry, and for packages that have a complex install script that requires manual install directory setting. See https://github.com/orgs/chocolatey-community/discussions/2254

@AdmiringWorm AdmiringWorm added enhancement New feature or request core extension labels Feb 10, 2024
@AdmiringWorm
Copy link
Member

My thoughts around this is to introduce two new cmdlets with a similar name to the Get-AppInstallLocation that is already implemented.

  1. Add the cmdlet Set-AppInstallLocation, which should have the responsibilities of:
    • Should have the parameters -LiteralPath and -Force. Literal Path should be mandatory (could potentially have -Path as an alternative that allows globbing, but not sure how useful that is)
    • It should verify whether the environment variable is already set or not, and only override the environment variable if it isn't set (both null, and an empty value) unless -Force is also used.
    • It should verify that the path specified exists, if it doesn't exist, it should throw an exception.
    • It should have an output value of the path that was set.
  2. Add the cmdlet Update-AppInstallLocation, which should have the responsibilities of:
    • Should have the parameters -AppNamePattern and -Force where AppNamePattern is mandatory.
    • It should call Get-AppInstallLocation to get the correct install location.
    • It should throw an exception if the installation path could not be found.
    • It should verify whether the environment variable is already set or not, and only override the environment variable if it isn't set (both null, and an empty value) unless -Force is also used.
    • It should have an output value of the path that was set.

Alternatively to the second cmdlet, we could also just have the first one but make LiteralPath/Path and AppNamePattern be mandatory in different sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core extension enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants