From eb5d78ac64ae605f910729c9b178097f30185484 Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 23 Nov 2020 19:27:45 -0800 Subject: [PATCH] (#13) Default to get local environment Add a flag for All environments --- public/Get-VagrantEnvironment.ps1 | 51 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/public/Get-VagrantEnvironment.ps1 b/public/Get-VagrantEnvironment.ps1 index bfd9969..03210ef 100644 --- a/public/Get-VagrantEnvironment.ps1 +++ b/public/Get-VagrantEnvironment.ps1 @@ -16,30 +16,47 @@ function Get-VagrantEnvironment { #> [cmdletBinding()] - Param() + Param( + [switch] + $All + ) process { + if ($All) { + $environments = vagrant global-status - $environments = vagrant global-status - - $environments = $environments[2..$($environments.Length-8)] - - Foreach($environment in $environments){ + $environments = $environments[2..$($environments.Length - 8)] + Foreach ($environment in $environments) { - if($environment -match "^(?[\w]+)\s+(?[\w\-._]+)\s+(?[\w]+)\s+(?[\w]+)\s+(?[\/\-\w:]+)"){ - - [pscustomobject]@{ - Id = $matches.id - Name = $matches.name - Provider = $matches.provider - State = $matches.state - Path = $matches.path - } + if ($environment -match "^(?[\w]+)\s+(?[\w\-._]+)\s+(?[\w]+)\s+(?[\w]+)\s+(?[\/\-\w:]+)") { + [pscustomobject]@{ + Id = $matches.id + Name = $matches.name + Provider = $matches.provider + State = $matches.state + Path = $matches.path + } + } + } + } + else { + $environments = vagrant status + $environments = $environments[2..$($environments.Length - 4)] + + foreach($environment in $environments){ + if ($environment -match "^(?[\w\-._]+)\s+(?[\w]+)\s+\((?[\w]+)\)") { + [pscustomobject]@{ + Name = $matches.name + Provider = $matches.provider + State = $matches.state + } + + } + } } - } -} \ No newline at end of file +}