psget/psget — pull request #135 by flofreud (2014-07-06 22:40:21+00:00)
Title: Cleanup refactoring

First of all I hope this is reviewable. The pull request changes vast amounts of code lines and i meld down all the small steps to only 2 commits so it is no step-by-step review possible. I didn't commit my many small change commits, because it would be more confusing than anything else to review not only the changes but also my journey to a acceptable consistent code style for Powershell.

I believe that this commit of PsGet.psm1 works more or less exactly like the current master. The changes in functionality are described below.

The old test suite in the first commit runs successfully in PowerShell v2 and v3. All tests are also green in both versions for the second commit. Therefore the implementation should be doing it work quite well (but we have to admit that not all the corner cases are checked by the suite).

Refactoring of PsGet.psm1 with the goals:
- unification of code style
- matching style recommondations for PowerShell (eg function names following the approved verb convention also internally)
- reduction of duplicate code (e.g. DownloadModuleFromWeb and DumbDownloadModuleFromWeb)
- less implicit dependencies between the miscellaneous functions considering error checking and handling
- documentation of expectations on function users
- removing all cases where errors did not cleanup afterwards leaving temp-files

Change in functionality:
- Preserve the default PSModulePath if the environment variable is not defined for user or machine on persisting.
- PsGet will remove all created temp files (if not stopped by ctrl-c).
- Refactor the tests to a more consistent code style and improved the isolation of the tests. No temp files or environment variable changes remain after test execution anymore (if not stopped by ctrl-c).

For code style is more or less:
* Language keywords lowercased
* Function and variable cased like defined
* Function parameters begin with a uppercase
* Local variables with a lowercase
* Braces are placed like in C#
* SYNOPSIS of a function is places at top
* Function top is easier to find as the end for reference
* Double quoted string are only used if format is necessary to signal that the string use format

Considered Links:
[http://ramblingcookiemonster.wordpress.com/2013/12/08/building-powershell-functions-best-practices/]
[http://msdn.microsoft.com/en-us/library/ff926074.aspx]
[http://windowsitpro.com/blog/my-12-powershell-best-practices]
[http://stackoverflow.com/questions/2025989/what-is-the-recommended-coding-style-for-powershell]
[http://blog.octo.com/en/powershell-v2-my-best-practices/]