language-powershell icon indicating copy to clipboard operation
language-powershell copied to clipboard

Updated 'Function' Snippets

Open vScripter opened this issue 9 years ago • 7 comments

  • Updated 'Function Cmdlet' snippet to include some best practices
    • Moved comment based help inside the function, which makes it more compatible/easier to work with when converting/copy/pasting code into modules or other scripts
    • Added additional detail in comment based help
    • Added some spacing to the syntax
    • Added .NET type names for parameters
  • Added new 'Advanced Function Cmdlet' snippet
    • This includes expanded support for try/catch blocks in each code section

I'm not a CoffeeScript expert; some of the formatting may need updated and/or other best practice followed.

vScripter avatar Nov 18 '15 18:11 vScripter

Thanks for this! i'll be taking a look at it momentarily.

jrsconfitto avatar Nov 19 '15 12:11 jrsconfitto

The test failures appear unrelated.

jrsconfitto avatar Nov 19 '15 12:11 jrsconfitto

These are very nice and provide a lot of guidance, thanks!

i'd prefer that the function snippet be simpler. For just writing a function, i'm not sure the Begin, Process, and End blocks are all necessary. Those seemed well covered in the advanced function snippet. Would you be interested in simplifying that snippet?

i think i'd prefer that there be another snippet to provide documentation generation (maybe we replace the current doc snippets with your stuff) so that users can choose to add it. Do you agree? Would you mind making that switch?

We could even make the Begin, Process, End, its own snippet too.

i'm not writing powershell for more than a couple scripts to build, test, and deploy NuGets so i'm very open to input.

i'll try to get those tests fixed! They aren't very helpful in their current state!

jrsconfitto avatar Nov 19 '15 12:11 jrsconfitto

I'm glad you made all of those points; I was actually thinking, after I finished the mods in this PR, about adding a greater level of modularity and breaking out snippets for:

  • Comment Based Help
  • Advanced Function (just keep the one that I already created)
  • Function (Simple)
    • Take out the comment based help
    • Only leave the Process block after the function declaration.
      • (it's considered a best practice to keep code in a Process block, at the very least, when writing functions. If you don't put code in a Process block, the PowerShell engine executes all of the code as if were running in the End block, which can affect function execution/behavior, particularity when accepting pipeline input.)

I have some ideas on how we can achieve that; I'll make some edits and commit the changes to this PR.

vScripter avatar Nov 19 '15 16:11 vScripter

Yeah this sounds great. I'm excited to see it :)

On Nov 19, 2015, at 11:21 AM, Kevin Kirkpatrick [email protected] wrote:

I'm glad you made all of those points; I was actually thinking, after I finished the mods in this PR, about adding a greater level of modularity and breaking out snippets for:

Comment Based Help Advanced Function (just keep the one that I already created) Function (Simple) Take out the comment based help Only leave the Process block after the function declaration. (it's considered a best practice to keep code in a Process block, at the very least, when writing functions. If you don't put code in a Process block, the PowerShell engine executes all of the code as if were running in the End block, which can affect function execution/behavior, particularity when accepting pipeline input.) I have some ideas on how we can achieve that; I'll make some edits and commit the changes to this PR.

— Reply to this email directly or view it on GitHub.

jrsconfitto avatar Nov 19 '15 16:11 jrsconfitto

If you merge in master, i think you may get the test fixes i tried to make as well.

jrsconfitto avatar Nov 19 '15 17:11 jrsconfitto

Okay, cool; I'll update my remote branch before I commit.

vScripter avatar Nov 19 '15 19:11 vScripter