mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Add Exit-Json and Fail-Json powershell helper functions
This commit is contained in:
parent
74c43c94cf
commit
97f4f56286
5 changed files with 21 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue