mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Add Exit-Json and Fail-Json powershell helper functions
This commit is contained in:
@@ -47,3 +47,20 @@ Function Set-Attr($obj, $name, $value)
|
||||
$obj | Add-Member -Force -MemberType NoteProperty -Name $name -Value $value
|
||||
}
|
||||
|
||||
# Helper function to convert a powershell object to JSON to echo it, exiting
|
||||
# the script
|
||||
Function Exit-Json($obj)
|
||||
{
|
||||
echo $obj | ConvertTo-Json
|
||||
Exit
|
||||
}
|
||||
|
||||
# Helper function to add the "msg" property and "failed" property, convert the
|
||||
# powershell object to JSON and echo it, exiting the script
|
||||
Function Fail-Json($obj, $message)
|
||||
{
|
||||
Set-Attr $obj "msg" $message
|
||||
Set-Attr $obj "failed" $true
|
||||
echo $obj | ConvertTo-Json
|
||||
Exit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user