Functions/Open-Repo.ps1


function Open-Repo {
    param(
        [string]
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = "The name of the repository that you wish to synchronize (e.g. Namespace/RepoName)")]
        $Repo,

        [string]
        [Parameter(HelpMessage = "The service hosting your repository (e.g. github.com)")]
        [ValidateSet("github.com", "dev.azure.com", "gitlab.com", "bitbucket.org")]
        $Service = "github.com",

        [string]
        [Parameter(HelpMessage = "The directory within which your repositories will be checked out (e.g. /src/)")]
        $Path = $GitTool.Directory
    )

    $info = Get-RepoInfo -Repo $Repo -Service $Service -Path $Path

    if (-not $info.Exists) {
        Write-Error -Category ResourceExists -Message "The repository $Service/$Repo does not exist." -RecommendedAction "Use New-Repo to create it."
        return
    }

    Set-Location -Path $info.Path

    return $info
}

Register-ArgumentCompleter -CommandName Open-Repo -ParameterName Repo -ScriptBlock $Function:SuggestRepoName