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

Amend contributing documentation with a guide on how we write C# Cmdlets for PowerShell #3539

Open
2 tasks done
Tracked by #3477
vexx32 opened this issue Oct 28, 2024 · 0 comments
Open
2 tasks done
Tracked by #3477

Comments

@vexx32
Copy link
Member

vexx32 commented Oct 28, 2024

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my request.

Is Your Feature Request Related To A Problem? Please describe.

No response

Describe The Solution. Why is it needed?

We need to amend the contribution documentation in this repository to include some information about how we tend to author C# cmdlets, classes and design patterns to make use of and those to avoid as well.

Specifically, we should include the following information:

  • Cmdlets should inherit from ChocolateyCmdlet and not Cmdlet or PSCmdlet
  • When and how to make use of SupportsShouldProcess aka -WhatIf / -Confirm
  • Cmdlets should contain minimal to no core logic, anything that other cmdlets need to make use of should be provided as part of a helper class, since calling into other C# cmdlets is not something that can or should really be done directly.
  • Usage and extension of existing helpers like PSHelper or ChocolateyCmdlet and so forth
  • How to manage error handling, and where
    • Exceptions should be thrown in core logic, caught and rethrown using ThrowTerminatingError() or WriteError() in the cmdlet layer itself
  • Dependency injection must be avoided, at least in anything that's in the cmdlet layer itself (inheriting ChocolateyCmdlet) as PowerShell does not support this.
  • Some guidance on communication between Chocolatey CLI and cmdlets, which is typically mediated with environment variables.
  • Under no circumstances should there be a direct dependency on CLI code from the cmdlets project, they need to remain separate.

Additional Context

No response

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant