Skip to content

Commit

Permalink
(steviecoaster#13) Add All switch
Browse files Browse the repository at this point in the history
all will do �agrant global-status while regular will now do �agrant status
  • Loading branch information
corbob committed Nov 24, 2020
1 parent 5aa38db commit 6a0bd12
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions public/Get-VagrantEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ function Get-VagrantEnvironment {
#>

[cmdletBinding()]
Param()
Param(
[switch]
$All
)

process {

$environments = vagrant global-status

$environments = $environments[2..$($environments.Length-8)]

$command = 'status'
$extraLines = 4
if($All){
$command = 'global-status'
$extraLines = 8
}
$environments = & vagrant $command
$environments = $environments[2..$($environments.Length - $extraLines)]
Foreach($environment in $environments){

# This is global-status environments
if($environment -match "^(?<id>[\w]+)\s+(?<name>[\w\-._]+)\s+(?<provider>[\w]+)\s+(?<state>[\w]+)\s+(?<path>[\/\-\w:]+)"){

[pscustomobject]@{
Id = $matches.id
Name = $matches.name
Expand All @@ -37,9 +43,17 @@ function Get-VagrantEnvironment {
}

}
# This is status environments
if($environment -match "^(?<name>[\w\-._]+)\s+(?<state>[\w]+)\s+\((?<provider>[\w]+)\)"){
[pscustomobject]@{
Name = $matches.name
Provider = $matches.provider
State = $matches.state
}

}

}

}

}
}

0 comments on commit 6a0bd12

Please sign in to comment.