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

SUGGESTION: Version Checking - xRequires #47

Closed
chelnak opened this issue Sep 10, 2016 · 5 comments
Closed

SUGGESTION: Version Checking - xRequires #47

chelnak opened this issue Sep 10, 2016 · 5 comments
Assignees

Comments

@chelnak
Copy link
Contributor

chelnak commented Sep 10, 2016

@jonathanmedd

I was having a play around with some PS stuff and thought it could be cool to implement the API Verison check with a declarative helper function.. e.g:

    function Get-Example {

        # This function does not support API versions lower than Version 7
        xRequires -Version 7 -Context $MyInvocation

    }

The code

function xRequires {
<#
    .SYNOPSIS
    Sets the required API Version for the current function

    .DESCRIPTION
    Sets the required API Version for the current function

    .PARAMETER Version
    The API Version that the function supports 

    .PARAMETER Context
    The functions execution context. This shold alwasy be $MyInvocation

    .INPUTS
    System.Int
    System.Management.Automation.PSObject.

    .OUTPUTS
    None

    .EXAMPLE

    function Get-Example {

        # This function does not support API versions lower than Version 7
        xRequires -Version 7 -Context $MyInvocation

    }

#>

[CmdletBinding()]

    Param (

        [Parameter(Mandatory=$true)]
        [Int]$Version,

        [Parameter(Mandatory=$true)]
        [PSCustomobject]$Context

    )

    if ($Global:vRAConnection.APIVersion) {

        if ($Global:vRAConnection.APIVersion -lt $Version) {

            throw "$($Context.MyCommand) is not supported with vRA API version $($Global:vRAConnection.APIVersion)"

        }

    }

}
@jonathanmedd
Copy link
Contributor

Good news. It seems like there is a general consensus to name Private Functions without the Verb-Noun standard, so xRequires is cool.

Have implemented a suggested solution, scoping was a bit of an issue putting private functions in a nested module. It seems like the consensus is to put them in a ps1 file and run the script via a reference in the manifest.

Take a look @chelnak and see what you think before I update all the other functions that need an API check

@chelnak
Copy link
Contributor Author

chelnak commented Sep 12, 2016

Nice job!

What do you think about splitting the private functions out in to their own files? E.g. xRequires.ps1

There would be no functional benifit.. only consistency with the way we present the public functions.

Happy either way.

@jonathanmedd
Copy link
Contributor

Yep, that would make sense. I'll update it and make sure all works well, but I reckon that is the way ahead

@jonathanmedd
Copy link
Contributor

@chelnak Updated. Let me know you are happy with it and I'll update all the functions to use it

@jonathanmedd
Copy link
Contributor

Code has been merged into Develop

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

2 participants