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

(#13) Default Get-VagrantEnvironment to get local environment #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions public/Get-VagrantEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 "^(?<id>[\w]+)\s+(?<name>[\w\-._]+)\s+(?<provider>[\w]+)\s+(?<state>[\w]+)\s+(?<path>[\/\-\w:]+)"){

[pscustomobject]@{
Id = $matches.id
Name = $matches.name
Provider = $matches.provider
State = $matches.state
Path = $matches.path
}
if ($environment -match "^(?<id>[\w]+)\s+(?<name>[\w\-._]+)\s+(?<provider>[\w]+)\s+(?<state>[\w]+)\s+(?<path>[\/\-\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)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically not needed (and will be incorrect depending on the state of the vagrant environment). We're matching the regex below, all of the mentioned lines won't match the regex...


foreach($environment in $environments){
if ($environment -match "^(?<name>[\w\-._]+)\s+(?<state>[\w]+)\s+\((?<provider>[\w]+)\)") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is subtley wrong... Two states that I've seen are not created which won't be picked up and running which will. Further: the name can include non-word characters like -.

[pscustomobject]@{
Name = $matches.name
Provider = $matches.provider
State = $matches.state
}

}
}
}

}

}
}