mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_regmerge: Clean up parameter handling (#21388)
Changes include: - Use Get-AnsibleParam with -type support - Replace $result PSObject with normal hash
This commit is contained in:
parent
dbb452100a
commit
edf2b00614
1 changed files with 14 additions and 13 deletions
|
@ -31,12 +31,13 @@ Function Convert-RegistryPath {
|
|||
Return $output
|
||||
}
|
||||
|
||||
$result = @{
|
||||
changed = $false
|
||||
}
|
||||
$params = Parse-Args $args
|
||||
$result = New-Object PSObject
|
||||
Set-Attr $result "changed" $False
|
||||
|
||||
$path = Get-Attr -obj $params -name path -failifempty $True -resultobj $result
|
||||
$compare_to = Get-Attr -obj $params -name compare_to -failifempty $False -resultobj $result
|
||||
$path = Get-AnsibleParam -obj $params -name "path" -type "path" -failifempty $true -resultobj $result
|
||||
$compare_to = Get-AnsibleParam -obj $params -name "compare_to" -type "str" -resultobj $result
|
||||
|
||||
# check it looks like a reg key, warn if key not present - will happen first time
|
||||
# only accepting PS-Drive style key names (starting with HKLM etc, not HKEY_LOCAL_MACHINE etc)
|
||||
|
@ -48,7 +49,7 @@ If ($compare_to) {
|
|||
If (Test-Path $compare_to_key -pathType container ) {
|
||||
$do_comparison = $True
|
||||
} Else {
|
||||
Set-Attr $result "compare_to_key_found" $False
|
||||
$result.compare_to_key_found = $false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,28 +72,28 @@ If ( $do_comparison -eq $True ) {
|
|||
$reg_import_args = @("IMPORT", "$path")
|
||||
$ret = & reg.exe $reg_import_args 2>&1
|
||||
If ($LASTEXITCODE -eq 0) {
|
||||
Set-Attr $result "changed" $True
|
||||
Set-Attr $result "difference_count" $comparison_result.count
|
||||
$result.changed = $true
|
||||
$result.difference_count = $comparison_result.count
|
||||
} Else {
|
||||
Set-Attr $result "rc" $LASTEXITCODE
|
||||
$result.rc = $LASTEXITCODE
|
||||
Fail-Json $result "$ret"
|
||||
}
|
||||
} Else {
|
||||
Set-Attr $result "difference_count" 0
|
||||
$result.difference_count = 0
|
||||
}
|
||||
|
||||
Remove-Item $exported_path
|
||||
Set-Attr $result "compared" $True
|
||||
$result.compared = $true
|
||||
|
||||
} Else {
|
||||
# not comparing, merge and report changed
|
||||
$reg_import_args = @("IMPORT", "$path")
|
||||
$ret = & reg.exe $reg_import_args 2>&1
|
||||
If ( $LASTEXITCODE -eq 0 ) {
|
||||
Set-Attr $result "changed" $True
|
||||
Set-Attr $result "compared" $False
|
||||
$result.changed = $true
|
||||
$result.compared = $false
|
||||
} Else {
|
||||
Set-Attr $result "rc" $LASTEXITCODE
|
||||
$result.rc = $LASTEXITCODE
|
||||
Fail-Json $result "$ret"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue