Skip to content

Commit

Permalink
Add remove commands
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiospizzi committed Apr 9, 2020
1 parent 8251f14 commit 5cb7c6d
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Adb/Adb.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
'Set-AdbItemProperty'
'Remove-AdbItemProperty'
'Add-AdbItemTemplate'
'Remove-AdbItemTemplate'
'Add-AdbItemParent'
'Remove-AdbItemParent'
# Item Validation
'Test-AdbItemValidation'
)
Expand Down
62 changes: 62 additions & 0 deletions Adb/Functions/Remove-AdbItemParent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<#
.SYNOPSIS
Remove the parent item from the adb item.
.DESCRIPTION
...
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
PS C:\> Remove-AdbItemParent -Name 'myname' -Parent 'myparent'
Remove the parent myparent from the item myname.
#>
function Remove-AdbItemParent
{
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
# The adb session.
[Parameter(Mandatory = $false)]
[PSTypeName('Adb.Session')]
[System.Object]
$Session,

# The item name.
[Parameter(Mandatory = $true)]
[System.String]
$Name,

# The parent to remove from the item.
[Parameter(Mandatory = $true)]
[System.String]
$Parent
)

$Session = Test-AdbSession -Session $Session

$item = Get-AdbItem -Session $Session -Name $Name

# Prepare the parent list
$parents = [System.String[]] $item.parentsNames
$parents = $parents | Where-Object { $_ -ne $Parent } | Sort-Object

$item = [PSCustomObject] @{
name = $Name
parentsNames = $parents
}

$requestSplat = Get-AdbSessionRequestSplat -Session $Session -Method 'Put'
$requestSplat['Uri'] = '{0}/items/{1}' -f $Session.Uri, $Name
$requestSplat['Body'] = $item | ConvertTo-Json -Compress -Depth 99

if ($PSCmdlet.ShouldProcess($requestSplat.Uri, $requestSplat.Method.ToUpper()))
{
Write-Verbose ('{0} {1} {2}' -f $requestSplat.Method.ToUpper(), $requestSplat.Uri, $requestSplat.Body)
Invoke-RestMethod @requestSplat -Verbose:$false -ErrorAction 'Stop' | Out-Null
}
}
64 changes: 64 additions & 0 deletions Adb/Functions/Remove-AdbItemTemplate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<#
.SYNOPSIS
Remove the template name from a the adb item.
.DESCRIPTION
This command will query all existing templates on the adb item, merge
them with the spcified template name and then update the new template
list.
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
PS C:\> Remove-AdmItemTemplate -Name 'myname' -Template 'mytpl'
Remove the template mytpl from the item myname.
#>
function Remove-AdbItemTemplate
{
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
# The adb session.
[Parameter(Mandatory = $false)]
[PSTypeName('Adb.Session')]
[System.Object]
$Session,

# The item name.
[Parameter(Mandatory = $true)]
[System.String]
$Name,

# The template to remove from the item.
[Parameter(Mandatory = $true)]
[System.String]
$Template
)

$Session = Test-AdbSession -Session $Session

$item = Get-AdbItem -Session $Session -Name $Name

# Prepare the template list
$templates = [System.String[]] $item.templatesNames
$templates = $templates | Where-Object { $_ -ne $Template } | Sort-Object

$item = [PSCustomObject] @{
name = $Name
templatesNames = $templates
}

$requestSplat = Get-AdbSessionRequestSplat -Session $Session -Method 'Put'
$requestSplat['Uri'] = '{0}/items/{1}' -f $Session.Uri, $Name
$requestSplat['Body'] = $item | ConvertTo-Json -Compress -Depth 99

if ($PSCmdlet.ShouldProcess($requestSplat.Uri, $requestSplat.Method.ToUpper()))
{
Write-Verbose ('{0} {1} {2}' -f $requestSplat.Method.ToUpper(), $requestSplat.Uri, $requestSplat.Body)
Invoke-RestMethod @requestSplat -Verbose:$false -ErrorAction 'Stop' | Out-Null
}
}
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

* Added: Command to add a template to an adb item
* Added: Command to add a parent to an adb item
* Added: Command to add and remove templates from the adb item
* Added: Command to add and remove parents from the adb item

## 1.3.0 - 2020-04-08

Expand Down

0 comments on commit 5cb7c6d

Please sign in to comment.