chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.04k stars 890 forks source link

(#310, #3318) Add Uninstall-ChocolateyPath cmdlet & rewrite associated functions as cmdlets #3440

Closed vexx32 closed 1 month ago

vexx32 commented 1 month ago

Description Of Changes

Motivation and Context

Partially, we just want to finally add Uninstall-ChocolateyPath. However, given overall contribution rates to the powershell functions are quite low, the decision has been made to rewrite our helper functions into C# cmdlets.

This PR serves as the initial set of cmdlets, a handful of useful example cases to prove out the viability of this approach, as well as ensuring that we have a better path forward for both OSS commands and any licensed commands we want to use in the future. It also opens up the possibility of more easily overriding the OSS cmdlets with a licensed command, and there are provisions in the chocolateyInstaller.psm1 module script to ensure that can work seamlessly.

Testing

  1. Using the add-path.zip package (renamed to .nupkg), attempt to install and uninstall the package running the chocolatey.console project in Visual Studio, specifying package parameters as /Path=C:\test /Scope=Machine (or other paths, or with /Scope=User).
  2. Build the project to completion and install the resulting package on a VM. Run the same test on this VM.
  3. Copy the installation of Chocolatey here to a folder that does not require administrative access, set $env:ChocolateyInstall to this folder, and attempt to run the same tests as before with the choco.exe in this folder. You should notice that any attempts to write to the Machine scope path fail with an error.
  4. In a PowerShell session, import the chocolatey installer module Import-Module $env:ChocolateyInstall/helpers/chocolateyInstaller.psm1 and check the Get-Help results for Install-ChocolateyPath, Uninstall-ChocolateyPath, and the other provided cmdlets. None of the cmdlets added/rewritten here should be missing help.

There will be a related PR to the licensed extension repository with some additional instructions to confirm the command overriding behaviour works and inheritance from this new assembly can function correctly.

For documentation generation:

  1. Ensure you have the chocolatey/docs repository cloned locally. (use the branch from this draft docs PR: https://github.com/chocolatey/docs/pull/993)
  2. Run the provided update-cmdlet-documentation.ps1 script, optionally providing the path to the docs repo folder with -DocsRepositoryPath if it is cloned in a folder that is not ../docs relative to the choco repository.

For the present I have included the XML rendition of the help in the repository, and I think it makes sufficient sense to just update this file whenever we need to; the markdown help can remain in the docs repository, and updating the XML help for this PowerShell module can be done as-needed and just committed to this repository.

The Invoke-Tests.ps1 file should also run the included Pester tests for these commands.

Operating Systems Testing

Win10

Change Types Made

Change Checklist

Related Issue

Fixes #310

Fixes #3318

gep13 commented 1 month ago

@vexx32 one other thing that I thought about yesterday, but didn't mention...

Can you update your commit messages to provide more information? If/when reviewing the commits directly, we won't have the same context that exists in this PR. I am thinking that all the information in the PR description should make its way into the commit messages.

Thoughts?

vexx32 commented 1 month ago

That sounds like rather a lot, but I don't disagree, I'll look to do that too.

EDIT: Done.

gep13 commented 1 month ago

@vexx32 can you let me know when the last remaining unresolved comments have been worked on? I would like to get this merged, so that we can continue with testing. Thanks

NOTE: I will mention here again, I forced pushed this PR on the head of develop, as I thought that it was ready for merging. You will need to reset you clone before continuing.

vexx32 commented 1 month ago

@gep13 I think I have everything sorted out, apologies for the wait on the last little bits here. :3

gep13 commented 1 month ago

@vexx32 thank you very much for your work on this! It is great to see this getting added!