Created
March 25, 2022 15:25
-
-
Save steviecoaster/957575eddb0c66bd0af97ec68fd76250 to your computer and use it in GitHub Desktop.
Crescendo module for parsing Vagrant native commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseVagrantBox { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[Object[]] | |
$Lines, | |
[Parameter()] | |
[String] | |
$Name | |
) | |
process { | |
$Boxes = [System.Collections.Generic.List[pscustomobject]]::new() | |
$Lines | Foreach-Object { | |
$null = $_ -match '(?<name>([\w\/]+))\s+\((?<provider>(\w+)),\s(?<version>(\d.+))\)' | |
$b = [pscustomObject]@{ | |
Name = $matches.name | |
Provider = $matches.provider | |
Version = [version]$matches.version | |
} | |
$Boxes.Add($b) | |
} | |
if(-not $Name){ | |
return $Boxes | |
} | |
else { | |
$r = $Boxes | Where-Object { $_.Name -eq $Name} | |
if(-not $r){ | |
Write-Warning "Box not found!" | |
} | |
else { | |
return $r | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseVagrantStatus { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[Object[]] | |
$Lines | |
) | |
process { | |
$Lines | Select-Object -SkipLast 7 | Foreach-Object { | |
$columns = ($_ -split "\s+").Trim() | Where-Object { $_ } | |
try { | |
$obj = [pscustomobject]@{ | |
Id = $columns[0] | |
Name = $columns[1] | |
Provider = $Columns[2] | |
State = $columns[3] | |
Directory = $columns[4] | |
} | |
if($obj.Id -ne 'id'){ | |
if($obj.Id -ne '-'){ | |
$obj | |
} | |
} | |
} | |
catch { | |
$null | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://aka.ms/PowerShell/Crescendo/Schemas/2021-11", | |
"Commands": [ | |
{ | |
"Verb": "Get", | |
"Noun": "VagrantStatus", | |
"OriginalName":"/usr/local/bin/vagrant", | |
"OriginalCommandElements": [ | |
"global-status" | |
], | |
"Description": "Shows Vagrant environment status of Vagrant boxes currently provisioned on your machine.", | |
"OutputHandlers": [ | |
{ | |
"ParameterSetName": "Default", | |
"Handler": "parseVagrantStatus", | |
"HandlerType": "Function" | |
} | |
] | |
}, | |
{ | |
"Verb": "Get", | |
"Noun": "VagrantBox", | |
"OriginalName": "/usr/local/bin/vagrant", | |
"OriginalCommandElements": [ | |
"box", | |
"list" | |
], | |
"Description": "Shows installed Vagrant boxes on a system", | |
"Parameters": [ | |
{ | |
"Name": "Name", | |
"ParameterType": "String", | |
"ParameterSetName": [ | |
"Default" | |
] | |
} | |
], | |
"OutputHandlers": [ | |
{ | |
"ParameterSetName": "Default", | |
"Handler": "parseVagrantBox", | |
"HandlerType": "Function" | |
} | |
] | |
}, | |
{ | |
"Verb": "Add", | |
"Noun": "VagrantBox", | |
"DefaultParameterSetName": "Default", | |
"OriginalName": "/usr/local/bin/vagrant", | |
"OriginalCommandElements": [ | |
"box", | |
"add" | |
], | |
"Description": "Adds a new Vagrant box to a given system", | |
"Parameters": [ | |
{ | |
"Name": "Shorthand", | |
"ParameterType": "string" | |
}, | |
{ | |
"Name": "CatalogFilePath", | |
"ParameterType": "string" | |
}, | |
{ | |
"Name": "CatalogUrl", | |
"ParameterType": "string" | |
}, | |
{ | |
"Name":"Force", | |
"ParameterType": "switch", | |
"OriginalName": "--force" | |
}, | |
{ | |
"Name":"DirectUrl", | |
"ParameterSetName": [ | |
"Direct" | |
], | |
"Mandatory": true, | |
"ParameterType": "string" | |
}, | |
{ | |
"Name":"Name", | |
"OriginalName": "--Name", | |
"ParameterType": "string", | |
"ParameterSetName": [ | |
"Direct" | |
], | |
"Mandatory": true | |
} | |
], | |
"SupportsShouldProcess": true | |
}, | |
{ | |
"Verb": "Stop", | |
"Noun": "VagrantMachine", | |
"OriginalName": "/usr/local/bin/vagrant", | |
"OriginalCommandElements": [ | |
"halt" | |
], | |
"Parameters": [ | |
{ | |
"Name": "Id", | |
"ParameterSetName": [ | |
"Default" | |
], | |
"ParameterType": "string" | |
} | |
], | |
"DefaultParameterSetName": "Default", | |
"SupportsShouldProcess": true | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Module manifest for module 'Vagrant' | |
# | |
# Generated by: svalding | |
# | |
# Generated on: 3/25/2022 | |
# | |
@{ | |
# Script module or binary module file associated with this manifest. | |
RootModule = 'Vagrant.psm1' | |
# Version number of this module. | |
ModuleVersion = '0.0.1' | |
# Supported PSEditions | |
# CompatiblePSEditions = @() | |
# ID used to uniquely identify this module | |
GUID = '4df9fb8b-35f6-4b4a-bcf6-3598a97c4732' | |
# Author of this module | |
Author = 'svalding' | |
# Company or vendor of this module | |
CompanyName = 'Unknown' | |
# Copyright statement for this module | |
Copyright = '(c) svalding. All rights reserved.' | |
# Description of the functionality provided by this module | |
# Description = '' | |
# Minimum version of the PowerShell engine required by this module | |
PowerShellVersion = '5.1.0' | |
# Name of the PowerShell host required by this module | |
# PowerShellHostName = '' | |
# Minimum version of the PowerShell host required by this module | |
# PowerShellHostVersion = '' | |
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | |
# DotNetFrameworkVersion = '' | |
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | |
# ClrVersion = '' | |
# Processor architecture (None, X86, Amd64) required by this module | |
# ProcessorArchitecture = '' | |
# Modules that must be imported into the global environment prior to importing this module | |
# RequiredModules = @() | |
# Assemblies that must be loaded prior to importing this module | |
# RequiredAssemblies = @() | |
# Script files (.ps1) that are run in the caller's environment prior to importing this module. | |
# ScriptsToProcess = @() | |
# Type files (.ps1xml) to be loaded when importing this module | |
# TypesToProcess = @() | |
# Format files (.ps1xml) to be loaded when importing this module | |
# FormatsToProcess = @() | |
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | |
# NestedModules = @() | |
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. | |
FunctionsToExport = 'Get-VagrantStatus', 'Get-VagrantBox', 'Add-VagrantBox', | |
'Stop-VagrantMachine' | |
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. | |
CmdletsToExport = @() | |
# Variables to export from this module | |
# VariablesToExport = @() | |
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. | |
AliasesToExport = @() | |
# DSC resources to export from this module | |
# DscResourcesToExport = @() | |
# List of all modules packaged with this module | |
# ModuleList = @() | |
# List of all files packaged with this module | |
# FileList = @() | |
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | |
PrivateData = @{ | |
PSData = @{ | |
# Tags applied to this module. These help with module discovery in online galleries. | |
Tags = 'CrescendoBuilt' | |
# A URL to the license for this module. | |
# LicenseUri = '' | |
# A URL to the main website for this project. | |
# ProjectUri = '' | |
# A URL to an icon representing this module. | |
# IconUri = '' | |
# ReleaseNotes of this module | |
# ReleaseNotes = '' | |
# Prerelease string of this module | |
# Prerelease = '' | |
# Flag to indicate whether the module requires explicit user acceptance for install/update/save | |
# RequireLicenseAcceptance = $false | |
# External dependent modules of this module | |
# ExternalModuleDependencies = @() | |
} # End of PSData hashtable | |
# CrescendoGenerated | |
CrescendoGenerated = '03/25/2022 11:21:39' | |
# CrescendoVersion | |
CrescendoVersion = '1.0.0' | |
} # End of PrivateData hashtable | |
# HelpInfo URI of this module | |
# HelpInfoURI = '' | |
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | |
# DefaultCommandPrefix = '' | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Module created by Microsoft.PowerShell.Crescendo | |
class PowerShellCustomFunctionAttribute : System.Attribute { | |
[bool]$RequiresElevation | |
[string]$Source | |
PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } | |
PowerShellCustomFunctionAttribute([bool]$rElevation) { | |
$this.RequiresElevation = $rElevation | |
$this.Source = "Microsoft.PowerShell.Crescendo" | |
} | |
} | |
function parseVagrantStatus { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[Object[]] | |
$Lines | |
) | |
process { | |
$Lines | Select-Object -SkipLast 7 | Foreach-Object { | |
$columns = ($_ -split "\s+").Trim() | Where-Object { $_ } | |
try { | |
$obj = [pscustomobject]@{ | |
Id = $columns[0] | |
Name = $columns[1] | |
Provider = $Columns[2] | |
State = $columns[3] | |
Directory = $columns[4] | |
} | |
if($obj.Id -ne 'id'){ | |
if($obj.Id -ne '-'){ | |
$obj | |
} | |
} | |
} | |
catch { | |
$null | |
} | |
} | |
} | |
} | |
function Get-VagrantStatus | |
{ | |
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)] | |
[CmdletBinding()] | |
param( ) | |
BEGIN { | |
$__PARAMETERMAP = @{} | |
$__outputHandlers = @{ | |
Default = @{ StreamOutput = $False; Handler = 'parseVagrantStatus' } | |
} | |
} | |
PROCESS { | |
$__boundParameters = $PSBoundParameters | |
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name | |
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) | |
$__commandArgs = @() | |
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) | |
if ($__boundParameters["Debug"]){wait-debugger} | |
$__commandArgs += 'global-status' | |
foreach ($paramName in $__boundParameters.Keys| | |
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| | |
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { | |
$value = $__boundParameters[$paramName] | |
$param = $__PARAMETERMAP[$paramName] | |
if ($param) { | |
if ($value -is [switch]) { | |
if ($value.IsPresent) { | |
if ($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
} | |
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } | |
} | |
elseif ( $param.NoGap ) { | |
$pFmt = "{0}{1}" | |
if($value -match "\s") { $pFmt = "{0}""{1}""" } | |
$__commandArgs += $pFmt -f $param.OriginalName, $value | |
} | |
else { | |
if($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
$__commandArgs += $value | Foreach-Object {$_} | |
} | |
} | |
} | |
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} | |
if ($__boundParameters["Debug"]){wait-debugger} | |
if ( $__boundParameters["Verbose"]) { | |
Write-Verbose -Verbose -Message /usr/local/bin/vagrant | |
$__commandArgs | Write-Verbose -Verbose | |
} | |
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] | |
if (! $__handlerInfo ) { | |
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present | |
} | |
$__handler = $__handlerInfo.Handler | |
if ( $PSCmdlet.ShouldProcess("/usr/local/bin/vagrant $__commandArgs")) { | |
# check for the application and throw if it cannot be found | |
if ( -not (Get-Command -ErrorAction Ignore "/usr/local/bin/vagrant")) { | |
throw "Cannot find executable '/usr/local/bin/vagrant'" | |
} | |
if ( $__handlerInfo.StreamOutput ) { | |
& "/usr/local/bin/vagrant" $__commandArgs | & $__handler | |
} | |
else { | |
$result = & "/usr/local/bin/vagrant" $__commandArgs | |
& $__handler $result | |
} | |
} | |
} # end PROCESS | |
<# | |
.DESCRIPTION | |
Shows Vagrant environment status of Vagrant boxes currently provisioned on your machine. | |
#> | |
} | |
function parseVagrantBox { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory)] | |
[Object[]] | |
$Lines, | |
[Parameter()] | |
[String] | |
$Name | |
) | |
process { | |
$Boxes = [System.Collections.Generic.List[pscustomobject]]::new() | |
$Lines | Foreach-Object { | |
$null = $_ -match '(?<name>([\w\/]+))\s+\((?<provider>(\w+)),\s(?<version>(\d.+))\)' | |
$b = [pscustomObject]@{ | |
Name = $matches.name | |
Provider = $matches.provider | |
Version = [version]$matches.version | |
} | |
$Boxes.Add($b) | |
} | |
if(-not $Name){ | |
return $Boxes | |
} | |
else { | |
$r = $Boxes | Where-Object { $_.Name -eq $Name} | |
if(-not $r){ | |
Write-Warning "Box not found!" | |
} | |
else { | |
return $r | |
} | |
} | |
} | |
} | |
function Get-VagrantBox | |
{ | |
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)] | |
[CmdletBinding()] | |
param( | |
[Parameter(ParameterSetName='Default')] | |
[String]$Name | |
) | |
BEGIN { | |
$__PARAMETERMAP = @{ | |
Name = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'String' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
} | |
$__outputHandlers = @{ | |
Default = @{ StreamOutput = $False; Handler = 'parseVagrantBox' } | |
} | |
} | |
PROCESS { | |
$__boundParameters = $PSBoundParameters | |
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name | |
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) | |
$__commandArgs = @() | |
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) | |
if ($__boundParameters["Debug"]){wait-debugger} | |
$__commandArgs += 'box' | |
$__commandArgs += 'list' | |
foreach ($paramName in $__boundParameters.Keys| | |
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| | |
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { | |
$value = $__boundParameters[$paramName] | |
$param = $__PARAMETERMAP[$paramName] | |
if ($param) { | |
if ($value -is [switch]) { | |
if ($value.IsPresent) { | |
if ($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
} | |
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } | |
} | |
elseif ( $param.NoGap ) { | |
$pFmt = "{0}{1}" | |
if($value -match "\s") { $pFmt = "{0}""{1}""" } | |
$__commandArgs += $pFmt -f $param.OriginalName, $value | |
} | |
else { | |
if($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
$__commandArgs += $value | Foreach-Object {$_} | |
} | |
} | |
} | |
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} | |
if ($__boundParameters["Debug"]){wait-debugger} | |
if ( $__boundParameters["Verbose"]) { | |
Write-Verbose -Verbose -Message /usr/local/bin/vagrant | |
$__commandArgs | Write-Verbose -Verbose | |
} | |
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] | |
if (! $__handlerInfo ) { | |
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present | |
} | |
$__handler = $__handlerInfo.Handler | |
if ( $PSCmdlet.ShouldProcess("/usr/local/bin/vagrant $__commandArgs")) { | |
# check for the application and throw if it cannot be found | |
if ( -not (Get-Command -ErrorAction Ignore "/usr/local/bin/vagrant")) { | |
throw "Cannot find executable '/usr/local/bin/vagrant'" | |
} | |
if ( $__handlerInfo.StreamOutput ) { | |
& "/usr/local/bin/vagrant" $__commandArgs | & $__handler | |
} | |
else { | |
$result = & "/usr/local/bin/vagrant" $__commandArgs | |
& $__handler $result | |
} | |
} | |
} # end PROCESS | |
<# | |
.DESCRIPTION | |
Shows installed Vagrant boxes on a system | |
.PARAMETER Name | |
#> | |
} | |
function Add-VagrantBox | |
{ | |
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)] | |
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Default')] | |
param( | |
[Parameter()] | |
[string]$Shorthand, | |
[Parameter()] | |
[string]$CatalogFilePath, | |
[Parameter()] | |
[string]$CatalogUrl, | |
[Parameter()] | |
[switch]$Force, | |
[Parameter(Mandatory=$true,ParameterSetName='Direct')] | |
[string]$DirectUrl, | |
[Parameter(Mandatory=$true,ParameterSetName='Direct')] | |
[string]$Name | |
) | |
BEGIN { | |
$__PARAMETERMAP = @{ | |
Shorthand = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
CatalogFilePath = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
CatalogUrl = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
Force = @{ | |
OriginalName = '--force' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'switch' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
DirectUrl = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
Name = @{ | |
OriginalName = '--Name' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
} | |
$__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } | |
} | |
PROCESS { | |
$__boundParameters = $PSBoundParameters | |
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name | |
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) | |
$__commandArgs = @() | |
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) | |
if ($__boundParameters["Debug"]){wait-debugger} | |
$__commandArgs += 'box' | |
$__commandArgs += 'add' | |
foreach ($paramName in $__boundParameters.Keys| | |
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| | |
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { | |
$value = $__boundParameters[$paramName] | |
$param = $__PARAMETERMAP[$paramName] | |
if ($param) { | |
if ($value -is [switch]) { | |
if ($value.IsPresent) { | |
if ($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
} | |
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } | |
} | |
elseif ( $param.NoGap ) { | |
$pFmt = "{0}{1}" | |
if($value -match "\s") { $pFmt = "{0}""{1}""" } | |
$__commandArgs += $pFmt -f $param.OriginalName, $value | |
} | |
else { | |
if($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
$__commandArgs += $value | Foreach-Object {$_} | |
} | |
} | |
} | |
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} | |
if ($__boundParameters["Debug"]){wait-debugger} | |
if ( $__boundParameters["Verbose"]) { | |
Write-Verbose -Verbose -Message /usr/local/bin/vagrant | |
$__commandArgs | Write-Verbose -Verbose | |
} | |
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] | |
if (! $__handlerInfo ) { | |
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present | |
} | |
$__handler = $__handlerInfo.Handler | |
if ( $PSCmdlet.ShouldProcess("/usr/local/bin/vagrant $__commandArgs")) { | |
# check for the application and throw if it cannot be found | |
if ( -not (Get-Command -ErrorAction Ignore "/usr/local/bin/vagrant")) { | |
throw "Cannot find executable '/usr/local/bin/vagrant'" | |
} | |
if ( $__handlerInfo.StreamOutput ) { | |
& "/usr/local/bin/vagrant" $__commandArgs | & $__handler | |
} | |
else { | |
$result = & "/usr/local/bin/vagrant" $__commandArgs | |
& $__handler $result | |
} | |
} | |
} # end PROCESS | |
<# | |
.DESCRIPTION | |
Adds a new Vagrant box to a given system | |
.PARAMETER Shorthand | |
.PARAMETER CatalogFilePath | |
.PARAMETER CatalogUrl | |
.PARAMETER Force | |
.PARAMETER DirectUrl | |
.PARAMETER Name | |
#> | |
} | |
function Stop-VagrantMachine | |
{ | |
[PowerShellCustomFunctionAttribute(RequiresElevation=$False)] | |
[CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Default')] | |
param( | |
[Parameter(ParameterSetName='Default')] | |
[string]$Id | |
) | |
BEGIN { | |
$__PARAMETERMAP = @{ | |
Id = @{ | |
OriginalName = '' | |
OriginalPosition = '0' | |
Position = '2147483647' | |
ParameterType = 'string' | |
ApplyToExecutable = $False | |
NoGap = $False | |
} | |
} | |
$__outputHandlers = @{ Default = @{ StreamOutput = $true; Handler = { $input } } } | |
} | |
PROCESS { | |
$__boundParameters = $PSBoundParameters | |
$__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name | |
$__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) | |
$__commandArgs = @() | |
$MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) | |
if ($__boundParameters["Debug"]){wait-debugger} | |
$__commandArgs += 'halt' | |
foreach ($paramName in $__boundParameters.Keys| | |
Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| | |
Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { | |
$value = $__boundParameters[$paramName] | |
$param = $__PARAMETERMAP[$paramName] | |
if ($param) { | |
if ($value -is [switch]) { | |
if ($value.IsPresent) { | |
if ($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
} | |
elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } | |
} | |
elseif ( $param.NoGap ) { | |
$pFmt = "{0}{1}" | |
if($value -match "\s") { $pFmt = "{0}""{1}""" } | |
$__commandArgs += $pFmt -f $param.OriginalName, $value | |
} | |
else { | |
if($param.OriginalName) { $__commandArgs += $param.OriginalName } | |
$__commandArgs += $value | Foreach-Object {$_} | |
} | |
} | |
} | |
$__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} | |
if ($__boundParameters["Debug"]){wait-debugger} | |
if ( $__boundParameters["Verbose"]) { | |
Write-Verbose -Verbose -Message /usr/local/bin/vagrant | |
$__commandArgs | Write-Verbose -Verbose | |
} | |
$__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] | |
if (! $__handlerInfo ) { | |
$__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present | |
} | |
$__handler = $__handlerInfo.Handler | |
if ( $PSCmdlet.ShouldProcess("/usr/local/bin/vagrant $__commandArgs")) { | |
# check for the application and throw if it cannot be found | |
if ( -not (Get-Command -ErrorAction Ignore "/usr/local/bin/vagrant")) { | |
throw "Cannot find executable '/usr/local/bin/vagrant'" | |
} | |
if ( $__handlerInfo.StreamOutput ) { | |
& "/usr/local/bin/vagrant" $__commandArgs | & $__handler | |
} | |
else { | |
$result = & "/usr/local/bin/vagrant" $__commandArgs | |
& $__handler $result | |
} | |
} | |
} # end PROCESS | |
<# | |
.SYNOPSIS | |
Usage: vagrant [options] <command> [<args>] | |
-h, --help Print this help. | |
Common commands: | |
autocomplete manages autocomplete installation on host | |
box manages boxes: installation, removal, etc. | |
cloud manages everything related to Vagrant Cloud | |
destroy stops and deletes all traces of the vagrant machine | |
global-status outputs status Vagrant environments for this user | |
halt stops the vagrant machine | |
help shows the help for a subcommand | |
hosts Information about hostnames managed by the vagrant-hosts plugin | |
init initializes a new Vagrant environment by creating a Vagrantfile | |
login | |
package packages a running vagrant environment into a box | |
plugin manages plugins: install, uninstall, update, etc. | |
port displays information about guest port mappings | |
powershell connects to machine via powershell remoting | |
provision provisions the vagrant machine | |
push deploys code in this environment to a configured destination | |
rdp connects to machine via RDP | |
reload restarts vagrant machine, loads new Vagrantfile configuration | |
resume resume a suspended vagrant machine | |
snapshot manages snapshots: saving, restoring, etc. | |
ssh connects to machine via SSH | |
ssh-config outputs OpenSSH valid configuration to connect to the machine | |
status outputs status of the vagrant machine | |
suspend suspends the machine | |
up starts and provisions the vagrant environment | |
upload upload to machine via communicator | |
validate validates the Vagrantfile | |
version prints current and latest Vagrant version | |
winrm executes commands on a machine via WinRM | |
winrm-config outputs WinRM configuration to connect to the machine | |
For help on any individual command run `vagrant COMMAND -h` | |
Additional subcommands are available, but are either more advanced | |
or not commonly used. To see all subcommands, run the command | |
`vagrant list-commands`. | |
--[no-]color Enable or disable color output | |
--machine-readable Enable machine readable output | |
-v, --version Display Vagrant version | |
--debug Enable debug output | |
--timestamp Enable timestamps on log output | |
--debug-timestamp Enable debug output with timestamps | |
--no-tty Enable non-interactive output | |
.DESCRIPTION See help for /usr/local/bin/vagrant | |
.PARAMETER Id | |
#> | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment