Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Updated 'Function' Snippets #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Updated 'Function' Snippets #47

wants to merge 2 commits into from

Conversation

vScripter
Copy link

  • 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.

Kevin Kirkpatrick added 2 commits November 18, 2015 13:09
Added 'Advanced Function Cmdlet' snippet. Syntax layout is based on
Microsoft and Community best practices.
- Updated 'Function Cmdlet' snippet to include some best practice
changes and spacing
- Updated 'Advanced Cmdlet Cmdlet' to include OutputType
@jrsconfitto
Copy link
Owner

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

@jrsconfitto
Copy link
Owner

The test failures appear unrelated.

@jrsconfitto
Copy link
Owner

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!

@vScripter
Copy link
Author

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.

@jrsconfitto
Copy link
Owner

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

On Nov 19, 2015, at 11:21 AM, Kevin Kirkpatrick notifications@github.com 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
Copy link
Owner

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

@vScripter
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

2 participants