Use of Mandatory parameter attribute [code consistency] #8004
wsmelton
started this conversation in
Contributors
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A number of things have dropped off in the project related to things we originally wanted to be consistent on across all commands. We are also adopting new patterns along the way as we have learned or found cleaner ways to do the same task/process (for readability).
A primary case though is the use of
Mandatory
parameter attribute which at the beginning we were 100% against using because the error/warning PowerShell spit out was not clear around the message it output. We opted to useTest-Bound
(which is no longer being used at all that I've seen) to verify if a parameter or set of parameters required were provided; if they were not thenStop-Function
was used to output a clear message.We have a mix of mandatory being used on
SqlInstance
and other parameters in a given command, while other commands are making use ofTest-Bound
. In another discussion (#7492) we brought up using snippets in VS Code to create our templates for both commands (as a whole) and snippets of code blocks to help be more consistent and show users a "best practice" approach.The main point is consistency because we have some commands now that if
SqlInstance
is not passed will get the red message from PowerShell, some don't spit out anything (e.g.Clear-DbaPlanCache
), and then some spit out a clean message visStop-Function
.Beta Was this translation helpful? Give feedback.
All reactions